123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using Prism.Commands;
- using Prism.Mvvm;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Controls;
- namespace PDF_Office.ViewModels.HomePanel.PDFTools
- {
- public class PDFToolsContentViewModel : BindableBase
- {
- #region 属性
- /// <summary>
- /// 扩展/收缩
- /// </summary>
- private bool _isExpendTools = false;
- public bool IsExpendTools
- {
- get { return _isExpendTools; }
- set { SetProperty(ref _isExpendTools, value); }
- }
- #endregion
- #region Command and Event
- public DelegateCommand<object> OpenMenuCommand { get; set; }
- public DelegateCommand ExpendCommand { get; set; }
- public event EventHandler<bool> ExpendToolsHanlder;
- #endregion
- public PDFToolsContentViewModel()
- {
- InitCommand();
- }
- private void InitCommand()
- {
- OpenMenuCommand = new DelegateCommand<object>(OpenMenu);
- ExpendCommand = new DelegateCommand(Expend);
- }
- private void Expend()
- {
- IsExpendTools = !IsExpendTools;
- ExpendToolsHanlder?.Invoke(null, IsExpendTools);
- }
- private void OpenMenu(object obj)
- {
- var menu = App.Current.FindResource("ExpendToolsContextMenu") as ContextMenu;
- var btn = obj as Button;
- if (menu != null && btn != null)
- {
- if (menu.Items.Count == 1)
- {
- var item = menu.Items[0] as MenuItem;
- if (_isExpendTools)
- {
- item.Header = "收缩";
- }
- else
- {
- item.Header = "展开";
- }
- item.Command = ExpendCommand;
- //btn.ContextMenu = menu;
- menu.PlacementTarget = btn;
- menu.IsOpen = true;
- }
- }
- }
- }
- }
|