1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- 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); }
- }
- private bool _isDropTools = false;
- public bool IsDropTools
- {
- get { return _isDropTools; }
- set { SetProperty(ref _isDropTools, value); }
- }
- #endregion
- #region Command and Event
- public DelegateCommand<object> OpenMenuCommand { get; set; }
- public DelegateCommand ExpendCommand { get; set; }
- public DelegateCommand<object> CustomCommand { get; set; }
- public event EventHandler<bool> ExpendToolsHanlder;
- #endregion
- public PDFToolsContentViewModel()
- {
- InitCommand();
- }
- private void InitCommand()
- {
- OpenMenuCommand = new DelegateCommand<object>(OpenMenu);
- ExpendCommand = new DelegateCommand(Expend);
- CustomCommand = new DelegateCommand<object>(Custom);
- }
- private void Custom(object obj)
- {
- IsDropTools = true;
- }
- 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;
- }
- }
- }
- }
- }
|