BOTAContentViewModel.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. namespace PDF_Office.ViewModels.BOTA
  16. {
  17. public class BOTAContentViewModel : BindableBase, INavigationAware
  18. {
  19. private CPDFViewer pdfViewer { get; set; }
  20. private IRegionManager regions { get; set; }
  21. private IDialogService dialogs { get; set; }
  22. public ViewContentViewModel viewContentViewModel { get; set; }
  23. private Dictionary<string, string> viewNameByTabItem;
  24. private string botaContentRegionName;
  25. public string BOTAContentRegionName
  26. {
  27. get { return botaContentRegionName; }
  28. set
  29. {
  30. SetProperty(ref botaContentRegionName, value);
  31. }
  32. }
  33. public string CurrentBar = "";
  34. public DelegateCommand<object> TabControlSelectionChangedCommand { get; set; }
  35. public BOTAContentViewModel(IRegionManager regionManager, IDialogService dialogService)
  36. {
  37. regions = regionManager;
  38. dialogs = dialogService;
  39. BOTAContentRegionName = Guid.NewGuid().ToString();
  40. TabControlSelectionChangedCommand = new DelegateCommand<object>(TabControlSelectionChangedEvent);
  41. viewNameByTabItem = new Dictionary<string, string>();
  42. InitDictionartViewNameByTabItem(ref viewNameByTabItem);
  43. }
  44. private void TabControlSelectionChangedEvent(object e)
  45. {
  46. var args = e as SelectionChangedEventArgs;
  47. if (args != null)
  48. {
  49. if (!string.IsNullOrEmpty((args.AddedItems[0] as TabItem).Name))
  50. {
  51. EnterSelectedBar((args.AddedItems[0] as TabItem).Name);
  52. viewContentViewModel.OpenBOTA = true;
  53. }
  54. }
  55. }
  56. /// <summary>
  57. /// 初始化名称-视图字典
  58. /// </summary>
  59. private void InitDictionartViewNameByTabItem(ref Dictionary<string, string> viewNameByTabItem)
  60. {
  61. //绑定tabitem名字和对应的View控件名称
  62. viewNameByTabItem.Add("TabItemThumbnail", "PageEditContent");
  63. viewNameByTabItem.Add("TabItemOutLine", "OutLineControl");
  64. viewNameByTabItem.Add("TabItemBookMark", "BookmarkContent");
  65. viewNameByTabItem.Add("TabItemAnnotation", "AnnotationContent");
  66. viewNameByTabItem.Add("TabItemSearch", "SearchContent");
  67. viewNameByTabItem.Add("TabItemForm", "");
  68. viewNameByTabItem.Add("TabItemSign", "");
  69. }
  70. /// <summary>
  71. /// 导航至目标TabItem
  72. /// </summary>
  73. /// <param name="currentBar"></param>
  74. private void EnterSelectedBar(string currentBar)
  75. {
  76. CurrentBar = currentBar;
  77. NavigationParameters param = new NavigationParameters();
  78. param.Add(ParameterNames.PDFViewer, pdfViewer);
  79. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  80. if (currentBar == "TabItemThumbnail")
  81. {
  82. param.Add(ParameterNames.BOTAThumb, true);
  83. }
  84. regions.RequestNavigate(BOTAContentRegionName, viewNameByTabItem[currentBar], param);
  85. }
  86. #region Navigate
  87. public bool IsNavigationTarget(NavigationContext navigationContext)
  88. {
  89. return true;
  90. }
  91. public void OnNavigatedFrom(NavigationContext navigationContext)
  92. {
  93. }
  94. public void OnNavigatedTo(NavigationContext navigationContext)
  95. {
  96. var contentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
  97. if (contentViewModel != null)
  98. {
  99. viewContentViewModel = contentViewModel;
  100. }
  101. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  102. if (pdfview != null)
  103. {
  104. pdfViewer = pdfview;
  105. }
  106. }
  107. #endregion Navigate
  108. }
  109. }