BackgroundTemplateListBaseContentViewModel.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. public EnumColorOrFile CurrentCreateMod;
  24. private string _currentTemplateListModName;
  25. public string CurrentTemplateListModName
  26. {
  27. get { return _currentTemplateListModName; }
  28. set { _currentTemplateListModName = value; }
  29. }
  30. private string backgroundTemplateListRegionName;
  31. public string BackgroundTemplateListRegionName
  32. {
  33. get => backgroundTemplateListRegionName;
  34. set => SetProperty(ref backgroundTemplateListRegionName, value);
  35. }
  36. private System.Windows.Visibility backgroundTemplateListVisible;
  37. public System.Windows.Visibility BackgroundTemplateListVisible
  38. {
  39. get => backgroundTemplateListVisible;
  40. set => SetProperty(ref backgroundTemplateListVisible, value);
  41. }
  42. private bool isFirstEnter = true;
  43. public bool IsFirstEnter
  44. {
  45. get => isFirstEnter;
  46. set => isFirstEnter = value;
  47. }
  48. public DelegateCommand<object> ChangeTemplateListModCommand { get; set; }
  49. public DelegateCommand EnterCreateCommand { get; set; }
  50. public string unicode = null;
  51. public string Unicode = null;
  52. public BackgroundTemplateListBaseContentViewModel(IRegionManager backgroundTemplateListRegion, IEventAggregator eventAggregator)
  53. {
  54. this.backgroundTemplateListRegion = backgroundTemplateListRegion;
  55. this.eventAggregator = eventAggregator;
  56. Unicode = App.mainWindowViewModel.SelectedItem.Unicode;
  57. BackgroundTemplateListRegionName = Guid.NewGuid().ToString();
  58. ChangeTemplateListModCommand = new DelegateCommand<object>(ChangeTemplateListMod);
  59. EnterCreateCommand = new DelegateCommand(EnterCreate);
  60. }
  61. public void EnterCreate()
  62. {
  63. this.eventAggregator.GetEvent<EnterTemplateListOrCreateEvent>().Publish(new EnumTemplateListOrCreateUnicode {Unicode=Unicode,Status= EnumTemplateListOrCreate.StatusCreate });
  64. }
  65. public void EnterSelectedTemplateListMod(string currentTemplateListName)
  66. {
  67. NavigationParameters param = new NavigationParameters();
  68. param.Add("UniCode", unicode);
  69. backgroundTemplateListRegion.RequestNavigate(BackgroundTemplateListRegionName, currentTemplateListName);
  70. backgroundTemplateListVisible = System.Windows.Visibility.Visible;
  71. }
  72. public void ChangeTemplateListMod(object e)
  73. {
  74. var args = e as Button;
  75. if (args != null)
  76. {
  77. CurrentTemplateListModName = args.Name;
  78. EnterSelectedTemplateListMod(CurrentTemplateListModName);
  79. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Publish(new stringUnicode {
  80. Unicode = Unicode,Status = CurrentTemplateListModName});
  81. }
  82. }
  83. public bool IsNavigationTarget(NavigationContext navigationContext)
  84. {
  85. return true;
  86. }
  87. public void OnNavigatedFrom(NavigationContext navigationContext)
  88. {
  89. }
  90. public void OnNavigatedTo(NavigationContext navigationContext)
  91. {
  92. navigationContext.Parameters.TryGetValue<string>("UniCode", out unicode);
  93. if (IsFirstEnter)
  94. {
  95. CurrentTemplateListModName = BackgroundTemplateListColorContentName;
  96. EnterSelectedTemplateListMod(CurrentTemplateListModName);
  97. IsFirstEnter = false;
  98. }
  99. else
  100. {
  101. navigationContext.Parameters.TryGetValue<EnumColorOrFile>("CurrentCreateModName", out CurrentCreateMod);
  102. if (CurrentCreateMod == EnumColorOrFile.StatusColor)
  103. {
  104. CurrentTemplateListModName = "BackgroundTemplateListColorContent";
  105. }
  106. else
  107. {
  108. CurrentTemplateListModName = "BackgroundTemplateListFileContent";
  109. }
  110. EnterSelectedTemplateListMod(CurrentTemplateListModName);
  111. eventAggregator.GetEvent<SetCurrentTemplateListModEvent>().Publish(new stringUnicode
  112. {
  113. Unicode = Unicode,
  114. Status = CurrentTemplateListModName
  115. });
  116. }
  117. }
  118. }
  119. }