MainWindow.xaml.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. namespace HistoryView.Views;
  2. public partial class MainWindow : Window
  3. {
  4. internal MainWindow(IEventAggregator eventAggregator, IRegionManager regionManager, MonitorHelper monitorHelper)
  5. {
  6. InitializeComponent();
  7. this._eventAggregator = eventAggregator;
  8. this._eventAggregator.GetEvent<WindowSwitch>().Subscribe(SwitchWindow);
  9. this.Loaded += MainWindow_Loaded;
  10. this._regionManager = regionManager;
  11. this._monitorHelper = monitorHelper;
  12. //MonitorHelper.LoadScreensInfo();
  13. }
  14. private readonly IRegionManager _regionManager;
  15. private readonly IEventAggregator _eventAggregator;
  16. private readonly MonitorHelper _monitorHelper;
  17. public static string DefaultRegion = "Monitor";
  18. private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  19. {
  20. //this.DragMove();
  21. }
  22. private void MainWindow_Loaded(object sender, RoutedEventArgs e)
  23. {
  24. this.PagesLoading ??= new Loading();
  25. this.Content = PagesLoading;
  26. }
  27. private object? PagesMainWindow;
  28. private object? PagesLoading;
  29. private object? PagesLogin;
  30. private void SwitchWindow()
  31. {
  32. Application.Current.Dispatcher.Invoke(() =>
  33. {
  34. this.WindowStartupLocation = WindowStartupLocation.CenterScreen;
  35. switch (this._eventAggregator.GetEvent<WindowSwitch>().Page)
  36. {
  37. case Pages.Loading:
  38. double screenWidth = System.Windows.SystemParameters.PrimaryScreenWidth;
  39. double screenHeight = System.Windows.SystemParameters.PrimaryScreenHeight;
  40. double windowWidth = this.Width;
  41. double windowHeight = this.Height;
  42. this.Left = (screenWidth / 2) - (windowWidth / 2);
  43. this.Top = (screenHeight / 2) - (windowHeight / 2);
  44. break;
  45. case Pages.Login:
  46. case Pages.MainWindow:
  47. this.SizeToContent = SizeToContent.Manual;
  48. this.WindowState = System.Windows.WindowState.Normal;
  49. this.WindowStyle = System.Windows.WindowStyle.None;
  50. this.ResizeMode = System.Windows.ResizeMode.NoResize;
  51. this.Topmost = false;
  52. if (!_monitorHelper.Monitors.TryGetValue(_monitorHelper.SelectedDisplay, out MonitorInfo? monitor) || monitor is null)
  53. {
  54. this.Left = 0;
  55. this.Top = 0;
  56. this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
  57. this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
  58. }
  59. else
  60. {
  61. this.Left = monitor.StartPixHorizontal;
  62. this.Top = monitor.StartPixVertical;
  63. this.Width = monitor.ResolutionHorizontal;
  64. this.Height = monitor.ResolutionVertical;
  65. }
  66. break;
  67. default:
  68. break;
  69. }
  70. switch (this._eventAggregator.GetEvent<WindowSwitch>().Page)
  71. {
  72. case Pages.Loading:
  73. this.PagesLoading ??= new Loading();
  74. this.Content = PagesLoading;
  75. break;
  76. case Pages.Login:
  77. this.PagesLogin ??= new Login();
  78. this.Content = PagesLogin;
  79. break;
  80. case Pages.MainWindow:
  81. this.PagesMainWindow ??= new Status();
  82. this.Content = PagesMainWindow;
  83. this._regionManager.Regions["ModuleContent"].RequestNavigate("GasPanel");
  84. this._regionManager.Regions["ModuleContent"].RequestNavigate(DefaultRegion);
  85. break;
  86. default:
  87. break;
  88. }
  89. });
  90. }
  91. private void Window_Closed(object sender, EventArgs e)
  92. {
  93. }
  94. }