WatermarkTemplateListBaseContentViewModel.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using PDF_Office.EventAggregators;
  2. using Prism.Commands;
  3. using Prism.Events;
  4. using Prism.Mvvm;
  5. using Prism.Regions;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Windows.Controls;
  10. namespace PDF_Office.ViewModels.EditTools.Watermark
  11. {
  12. public class WatermarkTemplateListBaseContentViewModel : BindableBase, INavigationAware
  13. {
  14. public IRegionManager watermarkTemplateListRegion;
  15. private readonly IEventAggregator eventAggregator;
  16. private string WatermarkTemplateListTextContentName = "WatermarkTemplateListTextContent";
  17. private string WatermarkTemplateListFileContentName = "WatermarkTemplateListFileContent";
  18. public bool IsFirstEnter=true;
  19. public EnumTextOrFile CurrentCreateMod;
  20. private string _currentTemplateListModName;
  21. public string CurrentTemplateListModName
  22. {
  23. get { return _currentTemplateListModName; }
  24. set { _currentTemplateListModName = value; }
  25. }
  26. private string watermarkTemplateListRegionName;
  27. public string WatermarkTemplateListRegionName
  28. {
  29. get => watermarkTemplateListRegionName;
  30. set => SetProperty(ref watermarkTemplateListRegionName, value);
  31. }
  32. private System.Windows.Visibility watermarkTemplateListVisible;
  33. public System.Windows.Visibility WatermarkTemplateListVisible
  34. {
  35. get => watermarkTemplateListVisible;
  36. set => SetProperty(ref watermarkTemplateListVisible, value);
  37. }
  38. public DelegateCommand<object> ChangeTemplateListModCommand { get; set; }
  39. public DelegateCommand EnterCreateCommand { get; set; }
  40. public WatermarkTemplateListBaseContentViewModel(IRegionManager watermarkTemplateListRegion, IEventAggregator eventAggregator)
  41. {
  42. this.watermarkTemplateListRegion = watermarkTemplateListRegion;
  43. this.eventAggregator = eventAggregator;
  44. WatermarkTemplateListRegionName = Guid.NewGuid().ToString();
  45. ChangeTemplateListModCommand = new DelegateCommand<object>(ChangeTemplateListMod);
  46. EnterCreateCommand = new DelegateCommand(EnterCreate);
  47. EnterSelectedTemplateListMod("WatermarkTemplateListColorContent");
  48. }
  49. public void EnterCreate()
  50. {
  51. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusCreate);
  52. }
  53. public void EnterSelectedTemplateListMod(string currentTemplateListName)
  54. {
  55. watermarkTemplateListRegion.RequestNavigate(WatermarkTemplateListRegionName, currentTemplateListName);
  56. watermarkTemplateListVisible = System.Windows.Visibility.Visible;
  57. }
  58. public void ChangeTemplateListMod(object e)
  59. {
  60. var args = e as Button;
  61. if (args != null)
  62. {
  63. CurrentTemplateListModName = args.Name;
  64. EnterSelectedTemplateListMod(CurrentTemplateListModName);
  65. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Publish(CurrentTemplateListModName);
  66. }
  67. }
  68. public bool IsNavigationTarget(NavigationContext navigationContext)
  69. {
  70. return true;
  71. }
  72. public void OnNavigatedFrom(NavigationContext navigationContext)
  73. {
  74. }
  75. public void OnNavigatedTo(NavigationContext navigationContext)
  76. {
  77. if (IsFirstEnter)
  78. {
  79. CurrentTemplateListModName = WatermarkTemplateListTextContentName;
  80. EnterSelectedTemplateListMod(CurrentTemplateListModName);
  81. IsFirstEnter = false;
  82. }
  83. else
  84. {
  85. navigationContext.Parameters.TryGetValue<EnumTextOrFile>("CurrentCreateModName", out CurrentCreateMod);
  86. if (CurrentCreateMod == EnumTextOrFile.StatusText)
  87. {
  88. CurrentTemplateListModName = WatermarkTemplateListTextContentName;
  89. }
  90. else
  91. {
  92. CurrentTemplateListModName = WatermarkTemplateListFileContentName;
  93. }
  94. EnterSelectedTemplateListMod(CurrentTemplateListModName);
  95. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Publish(CurrentTemplateListModName);
  96. }
  97. }
  98. }
  99. }