MainPage.xaml.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using System.Windows.Forms;
  2. using GalaSoft.MvvmLight.Ioc;
  3. using Muchinfo.MTPClient.Account.Views;
  4. using Muchinfo.MTPClient.Data.Enums;
  5. using Muchinfo.MTPClient.Infrastructure.Helpers;
  6. using Muchinfo.MTPClient.Infrastructure.MessageBox;
  7. using Muchinfo.MTPClient.Infrastructure.Utilities;
  8. using Muchinfo.MTPClient.IService;
  9. using Muchinfo.MTPClient.Resources;
  10. using Muchinfo.MTPClient.UI.Utilities;
  11. using Muchinfo.MTPClient.UI.ViewModels;
  12. using Muchinfo.PC.Common.Helpers;
  13. using Muchinfo.WPF.Controls.Windows;
  14. using System;
  15. using System.Windows;
  16. using System.Windows.Input;
  17. using System.Windows.Threading;
  18. using KeyEventArgs = System.Windows.Input.KeyEventArgs;
  19. namespace Muchinfo.MTPClient.UI.Views
  20. {
  21. /// <summary>
  22. /// MainView.xaml 的交互逻辑
  23. /// </summary>
  24. public partial class MainPage : Window
  25. {
  26. private Style windowMaxImageStyle;
  27. private Style windowImageStyle;
  28. public MainPage()
  29. {
  30. InitializeComponent();
  31. new WindowResizer(this,
  32. new WindowBorder(BorderPosition.TopLeft, TopLeftBorder),
  33. new WindowBorder(BorderPosition.Top, TopBorder),
  34. new WindowBorder(BorderPosition.TopRight, TopRightBorder),
  35. new WindowBorder(BorderPosition.Right, RightBorder),
  36. new WindowBorder(BorderPosition.BottomRight, BottomRightBorder),
  37. new WindowBorder(BorderPosition.Bottom, BottomBorder),
  38. new WindowBorder(BorderPosition.BottomLeft, BottomLeftBorder),
  39. new WindowBorder(BorderPosition.Left, LeftBorder));
  40. //避免窗口最大化时遮盖任务栏
  41. FullScreenManager.RepairWpfWindowFullScreenBehavior(this);
  42. // this.WindowState =WindowState.Maximized;
  43. this.SizeChanged += Home_SizeChanged;
  44. MessageRegister.Register(this);
  45. this.Loaded += Home_Loaded;
  46. this.KeyUp += MainPage_KeyUp;
  47. windowMaxImageStyle = ResourceHelper.GetFromeResource<Style>("WindowMaxImageStyle");
  48. windowImageStyle = ResourceHelper.GetFromeResource<Style>("WindowMaxImageStyle1");
  49. ////订阅行情
  50. //MessengerHelper.DefaultSend(string.Empty, MessengerTokens.QuoteSubscribe);
  51. MessengerHelper.DefaultRegister<string>(this, MessengerTokens.RegisterResourceChange, (e) =>
  52. {
  53. ////解决切换主题时菜单第一行没居中问题
  54. if (this.WindowState == WindowState.Maximized)
  55. {
  56. this.WindowState = WindowState.Minimized;
  57. this.WindowState = WindowState.Maximized;
  58. }
  59. });
  60. }
  61. private void MainPage_KeyUp(object sender, KeyEventArgs e)
  62. {
  63. var homeViewModel = this.DataContext as HomeViewModel;
  64. if (homeViewModel != null && homeViewModel.IsLockScreen)
  65. {
  66. if (e.Key == Key.Escape) homeViewModel.LoginOutCommand.Execute(null);
  67. }
  68. }
  69. private void Home_Loaded(object sender, RoutedEventArgs e)
  70. {
  71. var homeViewModel = this.DataContext as HomeViewModel;
  72. if (homeViewModel != null)
  73. {
  74. this.InputBindings.AddRange(homeViewModel.InitKeysCommand());
  75. }
  76. }
  77. private void Home_SizeChanged(object sender, SizeChangedEventArgs e)
  78. {
  79. MaxImageButton.Style = WindowState == WindowState.Maximized ? windowMaxImageStyle : windowImageStyle;
  80. }
  81. #region 窗口操作
  82. private void Window_MouseDown(object sender, MouseButtonEventArgs e)
  83. {
  84. if (e.LeftButton == MouseButtonState.Pressed)
  85. {
  86. DragMove();
  87. }
  88. if (e.ClickCount == 2)
  89. {
  90. this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
  91. }
  92. }
  93. private void WinMin_OnClick(object sender, RoutedEventArgs e)
  94. {
  95. this.WindowState = WindowState.Minimized;
  96. }
  97. private void WinMax_OnClick(object sender, RoutedEventArgs e)
  98. {
  99. this.WindowState = this.WindowState == WindowState.Maximized ? WindowState.Normal : WindowState.Maximized;
  100. }
  101. private void WinClose_OnClick(object sender, RoutedEventArgs e)
  102. {
  103. ////保存布局及列表行情抬头
  104. var messageResult = MessageBoxHelper.ShowQuestion(this, Client_Resource.UI2014_IsOrNotExit, Client_Resource.UI2014_Tips);
  105. if (messageResult == MessageBoxResult.Yes)
  106. {
  107. //手动发送登出消息
  108. if (UserManager.IsAccountLogin)
  109. {
  110. MessengerHelper.DefaultSend(string.Empty, MessengerTokens.SaveLayout);
  111. var service = SimpleIoc.Default.GetInstance<ILoginService>();
  112. if (service != null) service.TradeAccountLogout(UserManager.CurrentTradeAccount);
  113. }
  114. this.Close();
  115. }
  116. }
  117. #endregion
  118. private void UIElement_OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
  119. {
  120. var element = sender as FrameworkElement;
  121. if (e.NewValue.Equals(true) && element!=null)
  122. {
  123. this.Dispatcher.BeginInvoke(DispatcherPriority.Render, new Action(() =>
  124. {
  125. element.Focus();
  126. }));
  127. }
  128. }
  129. protected override void OnKeyUp(KeyEventArgs e)
  130. {
  131. base.OnKeyUp(e);
  132. var homeViewModel = this.DataContext as HomeViewModel;
  133. if (homeViewModel != null && e.Key == Key.Tab && Keyboard.Modifiers == ModifierKeys.Control)
  134. {
  135. homeViewModel.KeyCommand.Execute(CommandFunc.Tab);
  136. }
  137. }
  138. private void TradeSet_OnClick(object sender, RoutedEventArgs e)
  139. {
  140. var tradeSet = new TradeParamSetView()
  141. {
  142. Owner = System.Windows.Application.Current.MainWindow,
  143. WindowStartupLocation = WindowStartupLocation.CenterOwner
  144. };
  145. tradeSet.ShowDialog();
  146. }
  147. private void LockScreenBGGrid_OnKeyUp(object sender, KeyEventArgs e)
  148. {
  149. var homeViewModel = this.DataContext as HomeViewModel;
  150. if (homeViewModel != null && KeyGrid.IsKeyboardFocusWithin && e.Key == Key.Enter && homeViewModel.IsLockScreen)
  151. {
  152. homeViewModel.UnLockCommand.Execute(null);
  153. e.Handled = true;
  154. }
  155. }
  156. private void UIElement_OnKeyDown(object sender, KeyEventArgs e)
  157. {
  158. }
  159. }
  160. }