MainWindow.xaml.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. this.Width = 1024;
  59. this.Height = 768;
  60. }
  61. else
  62. {
  63. this.Left = 0;
  64. this.Top = 0;
  65. this.Width = 1024;
  66. this.Height = 768;
  67. //this.Left = monitor.StartPixHorizontal;
  68. //this.Top = monitor.StartPixVertical;
  69. //this.Width = monitor.ResolutionHorizontal;
  70. //this.Height = monitor.ResolutionVertical;
  71. }
  72. break;
  73. default:
  74. break;
  75. }
  76. switch (this._eventAggregator.GetEvent<WindowSwitch>().Page)
  77. {
  78. case Pages.Loading:
  79. this.PagesLoading ??= new Loading();
  80. this.Content = PagesLoading;
  81. break;
  82. case Pages.Login:
  83. this.PagesLogin ??= new Login();
  84. this.Content = PagesLogin;
  85. break;
  86. case Pages.MainWindow:
  87. this.PagesMainWindow ??= new Status();
  88. this.Content = PagesMainWindow;
  89. this._regionManager.Regions["ModuleContent"].RequestNavigate("GasPanel");
  90. this._regionManager.Regions["ModuleContent"].RequestNavigate(DefaultRegion);
  91. break;
  92. default:
  93. break;
  94. }
  95. });
  96. }
  97. private void Window_Closed(object sender, EventArgs e)
  98. {
  99. }
  100. }