BackgroundContentViewModel.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using Dropbox.Api.Sharing;
  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.Windows;
  9. using System.Linq;
  10. using System.Windows.Controls;
  11. using Visibility = System.Windows.Visibility;
  12. using Dropbox.Api.FileProperties;
  13. using ComPDFKitViewer.PdfViewer;
  14. using PDF_Office.Model;
  15. namespace PDF_Office.ViewModels.EditTools.Background
  16. {
  17. public class BackgroundContentViewModel : BindableBase, INavigationAware
  18. {
  19. public IEventAggregator eventAggregator;
  20. public IRegionManager backgroundRegion;
  21. private CPDFViewer PDFViewer;
  22. private ViewContentViewModel viewContentViewModel;
  23. public string TemplateListName = "BackgroundTemplateListBaseContent";
  24. public string CreateName = "BackgroundCreateBaseContent";
  25. public string CreateModColorName = "BackgroundCreateColorContent";
  26. public string CreateModFileName = "BackgroundCreateFileContent";
  27. public string BackgroundDocumentName = "BackgroundDocumentContent";
  28. private string _backgroundSettingsRegionName;
  29. /// <summary>
  30. /// 属性设置Region
  31. /// </summary>
  32. public string BackgroundSettingsRegionName
  33. {
  34. get { return _backgroundSettingsRegionName; }
  35. set { _backgroundSettingsRegionName = value; }
  36. }
  37. private Visibility _backgroundSettingsVisible = Visibility.Collapsed;
  38. /// <summary>
  39. /// 属性设置Region可见
  40. /// </summary>
  41. public Visibility BackgroundSettingsVisible
  42. {
  43. get { return _backgroundSettingsVisible; }
  44. set { _backgroundSettingsVisible = value; }
  45. }
  46. private string _backgroundDocumentRegionName;
  47. /// <summary>
  48. /// 持有Document的Region,负责渲染和保存
  49. /// </summary>
  50. public string BackgroundDocumentRegionName
  51. {
  52. get { return _backgroundDocumentRegionName; }
  53. set { _backgroundDocumentRegionName = value; }
  54. }
  55. private Visibility _backgroundDocumentVisible = Visibility.Visible;
  56. /// <summary>
  57. /// 持有Document的Region可见
  58. /// </summary>
  59. public Visibility BackgroundDocumentVisible
  60. {
  61. get { return _backgroundDocumentVisible; }
  62. set { _backgroundDocumentVisible = value; }
  63. }
  64. private EnumColorOrFile _currentCreateMod;
  65. public EnumColorOrFile CurrentCreateMod
  66. {
  67. get { return _currentCreateMod; }
  68. set { _currentCreateMod = value; }
  69. }
  70. /// <summary>
  71. /// 退出EditTool
  72. /// </summary>
  73. public DelegateCommand CloseEditToolCommand { get; set; }
  74. public DelegateCommand ConfirmEditToolCommand { get; set; }
  75. public DelegateCommand<string> EnterSelectedContentCommand { get; set; }
  76. public BackgroundContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  77. {
  78. this.eventAggregator = eventAggregator;
  79. this.backgroundRegion = regionManager;
  80. BackgroundSettingsVisible = Visibility.Visible;
  81. BackgroundSettingsRegionName = Guid.NewGuid().ToString();
  82. BackgroundDocumentRegionName = Guid.NewGuid().ToString();
  83. CloseEditToolCommand = new DelegateCommand(CloseEditTool);
  84. ConfirmEditToolCommand = new DelegateCommand(ConfirmEditTool);
  85. EnterSelectedContentCommand = new DelegateCommand<string>(EnterSelectedContent);
  86. eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Subscribe(EnterTemplateListOrCreate);
  87. eventAggregator.GetEvent<SetCurrentCreateModEvent>().Subscribe(SetCurrentCreateMod);
  88. }
  89. public void CloseEditTool()
  90. {
  91. this.eventAggregator.GetEvent<CloseEditToolEvent>().Publish();
  92. }
  93. public void ConfirmEditTool()
  94. {
  95. this.eventAggregator.GetEvent<ConfirmEditToolsBackgroundEvent>().Publish(CurrentCreateMod);
  96. }
  97. public void EnterTemplateListOrCreate(EnumTemplateListOrCreate enumTemplateListOrCreate)
  98. {
  99. if (enumTemplateListOrCreate == EnumTemplateListOrCreate.StatusTemplate)
  100. {
  101. EnterSelectedContent(TemplateListName);
  102. }
  103. else
  104. {
  105. EnterSelectedContent(CreateName);
  106. }
  107. }
  108. public void SetCurrentCreateMod(string currentCreateModName)
  109. {
  110. if (currentCreateModName == CreateModColorName)
  111. {
  112. CurrentCreateMod = EnumColorOrFile.StatusColor;
  113. }
  114. else if (currentCreateModName == CreateModFileName)
  115. {
  116. CurrentCreateMod = EnumColorOrFile.StatusFile;
  117. }
  118. }
  119. public void EnterSelectedContent(string SelectedContentName)
  120. {
  121. NavigationParameters param = new NavigationParameters();
  122. param.Add(ParameterNames.PDFViewer, PDFViewer);
  123. backgroundRegion.RequestNavigate(BackgroundSettingsRegionName, SelectedContentName, param);
  124. BackgroundSettingsVisible = Visibility.Visible;
  125. }
  126. public void EnterDocumentContent()
  127. {
  128. NavigationParameters param = new NavigationParameters();
  129. param.Add(ParameterNames.PDFViewer, PDFViewer);
  130. backgroundRegion.RequestNavigate(BackgroundDocumentRegionName, BackgroundDocumentName, param);
  131. BackgroundDocumentVisible = Visibility.Visible;
  132. }
  133. public void OnNavigatedTo(NavigationContext navigationContext)
  134. {
  135. navigationContext.Parameters.TryGetValue<ViewContentViewModel>(ParameterNames.ViewContentViewModel, out viewContentViewModel);
  136. navigationContext.Parameters.TryGetValue<CPDFViewer>(ParameterNames.PDFViewer, out PDFViewer);
  137. EnterSelectedContent(TemplateListName);
  138. EnterDocumentContent();
  139. }
  140. public bool IsNavigationTarget(NavigationContext navigationContext)
  141. {
  142. return true;
  143. }
  144. public void OnNavigatedFrom(NavigationContext navigationContext)
  145. {
  146. }
  147. }
  148. }