BOTAContentViewModel.cs 3.4 KB

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