BOTAContentViewModel.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. private 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. EnterSelectedBar((args.AddedItems[0] as TabItem).Name);
  50. viewContentViewModel.OpenBOTA = true;
  51. }
  52. }
  53. /// <summary>
  54. /// 初始化名称-视图字典
  55. /// </summary>
  56. private void InitDictionartViewNameByTabItem(ref Dictionary<string, string> viewNameByTabItem)
  57. {
  58. //绑定tabitem名字和对应的View控件名称
  59. viewNameByTabItem.Add("TabItemThumbnail", "PageEditContent");
  60. viewNameByTabItem.Add("TabItemOutLine", "OutLineControl");
  61. viewNameByTabItem.Add("TabItemBookMark", "BookmarkContent");
  62. viewNameByTabItem.Add("TabItemAnnotation", "AnnotationContent");
  63. viewNameByTabItem.Add("TabItemSearch", "SearchContent");
  64. viewNameByTabItem.Add("TabItemForm", "");
  65. viewNameByTabItem.Add("TabItemSign", "");
  66. }
  67. /// <summary>
  68. /// 导航至目标TabItem
  69. /// </summary>
  70. /// <param name="currentBar"></param>
  71. private void EnterSelectedBar(string currentBar)
  72. {
  73. CurrentBar = currentBar;
  74. NavigationParameters param = new NavigationParameters();
  75. param.Add(ParameterNames.PDFViewer, pdfViewer);
  76. param.Add(ParameterNames.ViewContentViewModel, viewContentViewModel);
  77. if (currentBar == "TabItemThumbnail")
  78. {
  79. param.Add(ParameterNames.BOTAThumb, true);
  80. }
  81. regions.RequestNavigate(BOTAContentRegionName, viewNameByTabItem[currentBar], param);
  82. }
  83. #region Navigate
  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. var contentViewModel = navigationContext.Parameters[ParameterNames.ViewContentViewModel] as ViewContentViewModel;
  94. if (contentViewModel != null)
  95. {
  96. viewContentViewModel = contentViewModel;
  97. }
  98. var pdfview = navigationContext.Parameters[ParameterNames.PDFViewer] as CPDFViewer;
  99. if (pdfview != null)
  100. {
  101. pdfViewer = pdfview;
  102. }
  103. }
  104. #endregion Navigate
  105. }
  106. }