PDFToolsContentViewModel.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using Prism.Commands;
  2. using Prism.Mvvm;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows.Controls;
  9. namespace PDF_Master.ViewModels.HomePanel.PDFTools
  10. {
  11. public class PDFToolsContentViewModel : BindableBase
  12. {
  13. #region 属性
  14. /// <summary>
  15. /// 扩展/收缩
  16. /// </summary>
  17. private bool _isExpendTools = false;
  18. public bool IsExpendTools
  19. {
  20. get { return _isExpendTools; }
  21. set { SetProperty(ref _isExpendTools, value); }
  22. }
  23. private bool _isDropTools = false;
  24. public bool IsDropTools
  25. {
  26. get { return _isDropTools; }
  27. set { SetProperty(ref _isDropTools, value); }
  28. }
  29. #endregion
  30. #region Command and Event
  31. public DelegateCommand<object> OpenMenuCommand { get; set; }
  32. public DelegateCommand ExpendCommand { get; set; }
  33. public DelegateCommand<object> CustomCommand { get; set; }
  34. public event EventHandler<bool> ExpendToolsHanlder;
  35. #endregion
  36. public PDFToolsContentViewModel()
  37. {
  38. InitCommand();
  39. }
  40. private void InitCommand()
  41. {
  42. OpenMenuCommand = new DelegateCommand<object>(OpenMenu);
  43. ExpendCommand = new DelegateCommand(Expend);
  44. CustomCommand = new DelegateCommand<object>(Custom);
  45. }
  46. private void Custom(object obj)
  47. {
  48. IsDropTools = true;
  49. }
  50. private void Expend()
  51. {
  52. IsExpendTools = !IsExpendTools;
  53. ExpendToolsHanlder?.Invoke(null, IsExpendTools);
  54. }
  55. private void OpenMenu(object obj)
  56. {
  57. var menu = App.Current.FindResource("ExpendToolsContextMenu") as ContextMenu;
  58. var btn = obj as Button;
  59. if (menu != null && btn != null)
  60. {
  61. if (menu.Items.Count == 1)
  62. {
  63. var item = menu.Items[0] as MenuItem;
  64. if (_isExpendTools)
  65. {
  66. item.Header = "收缩";
  67. }
  68. else
  69. {
  70. item.Header = "展开";
  71. }
  72. item.Command = ExpendCommand;
  73. //btn.ContextMenu = menu;
  74. menu.PlacementTarget = btn;
  75. menu.IsOpen = true;
  76. }
  77. }
  78. }
  79. }
  80. }