BackgroundTemplateListBaseContentViewModel.cs 5.3 KB

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