BackgroundCreateBaseContentViewModel.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. using ComPDFKitViewer.PdfViewer;
  2. using PDF_Office.EventAggregators;
  3. using PDF_Office.Model;
  4. using PDF_Office.Model.EditTools.Background;
  5. using PDF_Office.Views.EditTools.Background;
  6. using Prism.Commands;
  7. using Prism.Common;
  8. using Prism.Events;
  9. using Prism.Mvvm;
  10. using Prism.Regions;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows;
  17. using System.Windows.Controls;
  18. namespace PDF_Office.ViewModels.EditTools.Background
  19. {
  20. public class BackgroundCreateBaseContentViewModel : BindableBase, INavigationAware
  21. {
  22. IEventAggregator eventAggregator;
  23. IRegionManager backgroundCreateRegion;
  24. private CPDFViewer PDFViewer;
  25. public BackgroundInfo BackgroundInfo;
  26. private string backgroundCreateRegionName;
  27. public string BackgroundCreateRegionName
  28. {
  29. get => backgroundCreateRegionName;
  30. set => SetProperty(ref backgroundCreateRegionName, value);
  31. }
  32. private string _currentCreateModName;
  33. public string CurrentCreateModName
  34. {
  35. get => _currentCreateModName;
  36. set => _currentCreateModName = value;
  37. }
  38. private System.Windows.Visibility backgroundCreateVisible;
  39. public System.Windows.Visibility BackgroundCreateVisible
  40. {
  41. get => backgroundCreateVisible;
  42. set => SetProperty(ref backgroundCreateVisible, value);
  43. }
  44. private bool isFirstEnter = true;
  45. public bool IsFirstEnter
  46. {
  47. get => isFirstEnter;
  48. set => isFirstEnter = value;
  49. }
  50. private Visibility _createBaseVisible;
  51. public Visibility CreateBaseVisible
  52. {
  53. get => _createBaseVisible;
  54. set=>SetProperty(ref _createBaseVisible, value);
  55. }
  56. private Visibility _editBaseVisible;
  57. public Visibility EditBaseVisible
  58. {
  59. get => _editBaseVisible;
  60. set => SetProperty(ref _editBaseVisible, value);
  61. }
  62. public EnumColorOrFile CurrentTemplateListMod;
  63. public DelegateCommand<object> ChangeCreateModCommand { get; set; }
  64. public DelegateCommand EnterTemplateListCommand { get; set; }
  65. public DelegateCommand SaveToTemplateListCommand { get; set; }
  66. public DelegateCommand SaveToCurrentTemplateListCommand { get; set; }
  67. public BackgroundCreateBaseContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  68. {
  69. this.eventAggregator = eventAggregator;
  70. this.backgroundCreateRegion = regionManager;
  71. BackgroundCreateRegionName = Guid.NewGuid().ToString();
  72. ChangeCreateModCommand = new DelegateCommand<object>(ChangeCreateMod);
  73. EnterTemplateListCommand = new DelegateCommand(EnterTemplateList);
  74. SaveToTemplateListCommand = new DelegateCommand(SaveToTemplateList);
  75. SaveToCurrentTemplateListCommand = new DelegateCommand(SaveToCurrentTemplateList);
  76. }
  77. public void SaveToTemplateList()
  78. {
  79. if (CurrentCreateModName == "BackgroundCreateColorContent")
  80. {
  81. this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(EnumColorOrFile.StatusColor);
  82. }
  83. if (CurrentCreateModName == "BackgroundCreateFileContent")
  84. {
  85. this.eventAggregator.GetEvent<SaveBackgroundTemplateEvent>().Publish(EnumColorOrFile.StatusFile);
  86. }
  87. }
  88. public void SaveToCurrentTemplateList()
  89. {
  90. if (CurrentCreateModName == "BackgroundCreateColorContent")
  91. {
  92. eventAggregator.GetEvent<ConfirmEditBackgroundTemplateItemEvent>().Publish(EnumColorOrFile.StatusColor);
  93. }
  94. if (CurrentCreateModName == "BackgroundCreateFileContent")
  95. {
  96. eventAggregator.GetEvent<ConfirmEditBackgroundTemplateItemEvent>().Publish(EnumColorOrFile.StatusFile);
  97. }
  98. }
  99. public void EnterTemplateList()
  100. {
  101. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(EnumTemplateListOrCreate.StatusTemplate);
  102. }
  103. public void EnterSelectedCreateMod(string currentCreateName)
  104. {
  105. NavigationParameters param = new NavigationParameters();
  106. param.Add(ParameterNames.PDFViewer, PDFViewer);
  107. backgroundCreateRegion.RequestNavigate(BackgroundCreateRegionName, currentCreateName, param);
  108. backgroundCreateVisible = System.Windows.Visibility.Visible;
  109. }
  110. public void EditSelectedTemplateItem(string currentCreateName)
  111. {
  112. NavigationParameters param = new NavigationParameters();
  113. param.Add(ParameterNames.PDFViewer, PDFViewer);
  114. param.Add("BackgroundInfo", BackgroundInfo);
  115. backgroundCreateRegion.RequestNavigate(BackgroundCreateRegionName, currentCreateName, param);
  116. backgroundCreateVisible = System.Windows.Visibility.Visible;
  117. }
  118. public void ChangeCreateMod(object e)
  119. {
  120. var args = e as Button;
  121. if (args != null)
  122. {
  123. CurrentCreateModName = args.Name;
  124. EnterSelectedCreateMod(CurrentCreateModName);
  125. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(CurrentCreateModName);
  126. }
  127. }
  128. public bool IsNavigationTarget(NavigationContext navigationContext)
  129. {
  130. return true;
  131. }
  132. public void OnNavigatedFrom(NavigationContext navigationContext)
  133. {
  134. }
  135. public void OnNavigatedTo(NavigationContext navigationContext)
  136. {
  137. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  138. navigationContext.Parameters.TryGetValue<EnumColorOrFile>("CurrentTemplateListModName", out CurrentTemplateListMod);
  139. if (CurrentTemplateListMod == EnumColorOrFile.StatusColor)
  140. {
  141. CurrentCreateModName = "BackgroundCreateColorContent";
  142. }
  143. else
  144. {
  145. CurrentCreateModName = "BackgroundCreateFileContent";
  146. }
  147. if(navigationContext.Parameters.TryGetValue<BackgroundInfo>("BackgroundInfo", out BackgroundInfo))
  148. {
  149. EditSelectedTemplateItem(CurrentCreateModName);
  150. EditBaseVisible = Visibility.Visible;
  151. CreateBaseVisible= Visibility.Collapsed;
  152. }
  153. else
  154. {
  155. EnterSelectedCreateMod(CurrentCreateModName);
  156. CreateBaseVisible= Visibility.Visible;
  157. EditBaseVisible= Visibility.Collapsed;
  158. }
  159. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Publish(CurrentCreateModName);
  160. }
  161. }
  162. }