HomeContentViewModel.cs 4.3 KB

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