BackgroundTemplateListBaseContentViewModel.cs 4.5 KB

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