MainWindow.xaml.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using PDF_Office.ViewModels;
  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 System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using Prism.Events;
  18. using PDF_Office.EventAggregators;
  19. using PDF_Office.CustomControl;
  20. using Prism.Ioc;
  21. using PDF_Office.Helper;
  22. using System.IO;
  23. namespace PDF_Office.Views
  24. {
  25. /// <summary>
  26. /// MainWindow.xaml 的交互逻辑
  27. /// </summary>
  28. public partial class MainWindow : Window
  29. {
  30. public IEventAggregator aggregator;
  31. public IRegionManager region;
  32. public MainWindow()
  33. {
  34. InitializeComponent();
  35. }
  36. /// <summary>
  37. /// 此类因为Dragablz控件的原因需要特殊处理
  38. /// </summary>
  39. /// <param name="eventAggregator"></param>
  40. public MainWindow(IEventAggregator eventAggregator, IContainerProvider container) :this()
  41. {
  42. aggregator = eventAggregator;
  43. eventAggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Opened });
  44. }
  45. private void BtnMiniSize_Click(object sender, RoutedEventArgs e)
  46. {
  47. System.Windows.SystemCommands.MinimizeWindow(this);
  48. }
  49. private void BtnClose_Click(object sender, RoutedEventArgs e)
  50. {
  51. System.Windows.SystemCommands.CloseWindow(this);
  52. }
  53. private void BtnReStore_Click(object sender, RoutedEventArgs e)
  54. {
  55. if (this.WindowState == WindowState.Maximized)
  56. System.Windows.SystemCommands.RestoreWindow(this);
  57. else
  58. System.Windows.SystemCommands.MaximizeWindow(this);
  59. }
  60. private void Window_Activated(object sender, EventArgs e)
  61. {
  62. App.Current.MainWindow = this;
  63. aggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Activated });
  64. }
  65. private void Window_Closed(object sender, EventArgs e)
  66. {
  67. aggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Closed });
  68. }
  69. public void LoadPdfViewer(string[] filePaths)
  70. {
  71. var content = App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel;
  72. if (filePaths.Count() == 1)
  73. {
  74. if (App.OpenedFileList.Contains(filePaths[0]))
  75. {
  76. App.mainWindowViewModel.SelectItem(filePaths[0]);
  77. }
  78. else
  79. {
  80. content.OpenFile(filePaths[0]);
  81. }
  82. }
  83. else
  84. {
  85. var fileList = filePaths.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
  86. if (fileList.Count <= 0)
  87. return;
  88. content.OpenFile(filePaths[0]);
  89. for (int i = 1; i < fileList.Count(); i++)
  90. {
  91. if (!App.OpenedFileList.Contains(fileList[i]))
  92. {
  93. App.mainWindowViewModel.AddTabItem(fileList[i]);
  94. }
  95. }
  96. }
  97. }
  98. }
  99. }