HomeContentViewModel.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using Microsoft.Win32;
  2. using PDF_Office.EventAggregators;
  3. using Prism.Commands;
  4. using Prism.Events;
  5. using Prism.Mvvm;
  6. using Prism.Regions;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Diagnostics;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. namespace PDF_Office.ViewModels
  15. {
  16. public class HomeContentViewModel : BindableBase, INavigationAware
  17. {
  18. private string fileName = "Home";
  19. public string FileName
  20. {
  21. get { return fileName; }
  22. set { SetProperty(ref fileName, value); }
  23. }
  24. private string regionName;
  25. public string ToolRegionName
  26. {
  27. get { return regionName; }
  28. set { SetProperty(ref regionName, value); }
  29. }
  30. private Visibility isLoading = Visibility.Collapsed;
  31. public Visibility IsLoading
  32. {
  33. get { return isLoading; }
  34. set
  35. {
  36. SetProperty(ref isLoading, value);
  37. }
  38. }
  39. private MainContentViewModel mainContentViewModel;
  40. public DelegateCommand OpenFileCommand { get; set; }
  41. public DelegateCommand<string> ShowToolCommand { get; set; }
  42. public IRegionManager toolregion;
  43. public IEventAggregator eventer;
  44. public HomeContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
  45. {
  46. toolregion = regionManager;
  47. eventer = eventAggregator;
  48. ToolRegionName = Guid.NewGuid().ToString();
  49. OpenFileCommand = new DelegateCommand(OpenFile);
  50. ShowToolCommand = new DelegateCommand<string>(ShowToolContent);
  51. }
  52. /// <summary>
  53. /// 显示右侧不同的工具栏页面
  54. /// </summary>
  55. /// <param name="view"></param>
  56. public void ShowToolContent(string view)
  57. {
  58. toolregion.RequestNavigate(ToolRegionName, view);
  59. }
  60. /// <summary>
  61. /// 打开文件
  62. /// </summary>
  63. public void OpenFile()
  64. {
  65. OpenFileDialog openFileDialog = new OpenFileDialog();
  66. openFileDialog.Filter = "PDF Files (*.pdf)|*.pdf";
  67. openFileDialog.Multiselect = true;
  68. if ((bool)openFileDialog.ShowDialog())
  69. {
  70. if (openFileDialog.FileNames.Count() == 1)
  71. {
  72. if (App.OpenedFileList.Contains(openFileDialog.FileName))
  73. {
  74. App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
  75. }
  76. else
  77. {
  78. mainContentViewModel.OpenFile(openFileDialog.FileName);
  79. }
  80. }
  81. else
  82. {
  83. var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  84. if (fileList.Count <= 0)
  85. return;
  86. mainContentViewModel.OpenFile(fileList[0]);
  87. for (int i = 1; i < fileList.Count(); i++)
  88. {
  89. if (!App.OpenedFileList.Contains(fileList[i]))
  90. {
  91. App.mainWindowViewModel.AddTabItem(fileList[i]);
  92. }
  93. }
  94. }
  95. }
  96. }
  97. public void CreatBlankPDF()
  98. {
  99. }
  100. #region Navigate
  101. public void OnNavigatedTo(NavigationContext navigationContext)
  102. {
  103. var mainVM = navigationContext.Parameters["MainViewModel"] as MainContentViewModel;
  104. if (mainVM != null)
  105. {
  106. mainContentViewModel = mainVM;
  107. }
  108. }
  109. public bool IsNavigationTarget(NavigationContext navigationContext)
  110. {
  111. return true;
  112. }
  113. public void OnNavigatedFrom(NavigationContext navigationContext)
  114. {
  115. }
  116. #endregion
  117. }
  118. }