BOTAContentViewModel.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using Prism.Mvvm;
  2. using Prism.Regions;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using ComPDFKitViewer.PdfViewer;
  9. using PDF_Office.Model;
  10. using Prism.Commands;
  11. using System.Windows.Controls;
  12. using DryIoc;
  13. using Prism.Services.Dialogs;
  14. using PDF_Office.Views.PageEdit;
  15. using PDF_Office.Properties;
  16. namespace PDF_Office.ViewModels.BOTA
  17. {
  18. public class BOTAContentViewModel : BindableBase, INavigationAware
  19. {
  20. private CPDFViewer pdfViewer { get; set; }
  21. private IRegionManager regions { get; set; }
  22. private IDialogService dialogs { get; set; }
  23. public ViewContentViewModel viewContentViewModel { get; set; }
  24. private Dictionary<string, string> viewNameByTabItem;
  25. private string botaContentRegionName;
  26. public string BOTAContentRegionName
  27. {
  28. get { return botaContentRegionName; }
  29. set
  30. {
  31. SetProperty(ref botaContentRegionName, value);
  32. }
  33. }
  34. private int selectedIndex;
  35. public int SelectedIndex
  36. {
  37. get { return selectedIndex; }
  38. set
  39. {
  40. SetProperty(ref selectedIndex, value);
  41. }
  42. }
  43. public string CurrentBar = "";
  44. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  45. public BOTAContentViewModel(IRegionManager regionManager, IDialogService dialogService)
  46. {
  47. regions = regionManager;
  48. dialogs = dialogService;
  49. BOTAContentRegionName = Guid.NewGuid().ToString();
  50. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectionChangedEvent);
  51. viewNameByTabItem = new Dictionary<string, string>();
  52. InitDictionartViewNameByTabItem(ref viewNameByTabItem);
  53. }
  54. private void TabControlSelectionChangedEvent(object e)
  55. {
  56. var args = e as SelectionChangedEventArgs;
  57. if (args != null)
  58. {
  59. if (!string.IsNullOrEmpty((args.AddedItems[0] as TabItem).Name))
  60. {
  61. EnterSelectedBar((args.AddedItems[0] as TabItem).Name);
  62. viewContentViewModel.OpenBOTA = true;
  63. }
  64. }
  65. }
  66. /// <summary>
  67. /// 初始化名称-视图字典
  68. /// </summary>
  69. private void InitDictionartViewNameByTabItem(ref Dictionary<string, string> viewNameByTabItem)
  70. {
  71. //绑定tabitem名字和对应的View控件名称
  72. viewNameByTabItem.Add("TabItemThumbnail", "PageEditContent");
  73. viewNameByTabItem.Add("TabItemOutLine", "OutLineControl");
  74. viewNameByTabItem.Add("TabItemBookMark", "BookmarkContent");
  75. viewNameByTabItem.Add("TabItemAnnotation", "AnnotationContent");
  76. viewNameByTabItem.Add("TabItemSearch", "SearchContent");
  77. viewNameByTabItem.Add("TabItemForm", "");
  78. viewNameByTabItem.Add("TabItemSign", "");
  79. }
  80. /// <summary>
  81. /// 导航至目标TabItem
  82. /// </summary>
  83. /// <param name="currentBar"></param>
  84. private void EnterSelectedBar(string currentBar)
  85. {
  86. CurrentBar = currentBar;
  87. NavigationParameters param = new NavigationParameters();
  88. param.Add(ParameterNames.PDFViewer, pdfViewer);
  89. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  90. if (currentBar == "TabItemThumbnail")
  91. {
  92. param.Add(ParameterNames.BOTAThumb, true);
  93. }
  94. regions.RequestNavigate(BOTAContentRegionName, viewNameByTabItem[currentBar], param);
  95. }
  96. #region Navigate
  97. public bool IsNavigationTarget(NavigationContext navigationContext)
  98. {
  99. return true;
  100. }
  101. public void OnNavigatedFrom(NavigationContext navigationContext)
  102. {
  103. }
  104. public void OnNavigatedTo(NavigationContext navigationContext)
  105. {
  106. var contentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
  107. if (contentViewModel != null)
  108. {
  109. viewContentViewModel = contentViewModel;
  110. }
  111. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  112. if (pdfview != null)
  113. {
  114. pdfViewer = pdfview;
  115. }
  116. //大纲和文档同时打开
  117. if (Settings.Default.AppProperties.InitialVIew.ShowOutLine && pdfViewer.Document.GetOutlineList().Count > 0)
  118. {
  119. SelectedIndex = 2;
  120. EnterSelectedBar("TabItemOutLine");
  121. viewContentViewModel.OpenBOTA = true;
  122. }
  123. }
  124. #endregion Navigate
  125. }
  126. }