BOTAContentViewModel.cs 4.0 KB

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