diff --git a/SlnMesnac.WPF/MainWindow.xaml b/SlnMesnac.WPF/MainWindow.xaml index c4ec7d4..3fa52ad 100644 --- a/SlnMesnac.WPF/MainWindow.xaml +++ b/SlnMesnac.WPF/MainWindow.xaml @@ -44,7 +44,7 @@ - diff --git a/SlnMesnac.WPF/MainWindow.xaml.cs b/SlnMesnac.WPF/MainWindow.xaml.cs index 2139374..c80e35d 100644 --- a/SlnMesnac.WPF/MainWindow.xaml.cs +++ b/SlnMesnac.WPF/MainWindow.xaml.cs @@ -26,6 +26,24 @@ namespace SlnMesnac.WPF InitializeComponent(); this.DataContext = new MainWindowViewModel(); + //监听键盘按键事件,如果按ESC则关闭该窗口 + this.KeyDown += Esc_Exit_KeyDown; } + + + #region 按键:ESC关闭 + //监听键盘按键事件,如果按ESC则关闭该窗口 + private void Esc_Exit_KeyDown(object sender, KeyEventArgs e) + { + if (e.Key == Key.Escape) + { + this.Close(); + Application.Current.Shutdown(); + //获取该用户控件的上级窗口 + //Window wid = Window.GetWindow(this); + //wid.Close(); + } + } + #endregion } } diff --git a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs index 026bfb5..b41ae0d 100644 --- a/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs +++ b/SlnMesnac.WPF/ViewModel/MainWindowViewModel.cs @@ -7,6 +7,7 @@ using SlnMesnac.WPF.Page; using System; using System.Windows; +using System.Windows.Threading; namespace SlnMesnac.WPF.ViewModel { @@ -17,6 +18,13 @@ namespace SlnMesnac.WPF.ViewModel private HomePage homePage = new HomePage(); private LaminatePage laminatePage = new LaminatePage(); + private string _TimeNow; + public string TimeNow + { + get => _TimeNow; + set { _TimeNow = value; RaisePropertyChanged(); } + } + #region 参数定义 /// @@ -88,7 +96,26 @@ namespace SlnMesnac.WPF.ViewModel ControlOnClickCommand = new RelayCommand(obj => ControlOnClick(obj)); FormControlCommand = new RelayCommand(x => FormControl(x)); + + DispatcherTimer timer = new DispatcherTimer(DispatcherPriority.Send) + { + Interval = new TimeSpan(0, 0, 0, 1) + }; + timer.Tick += timer_Tick; + timer.IsEnabled = true; + + //监听键盘按键事件,如果按ESC则关闭该窗口 + // this.KeyDown += Esc_Exit_KeyDown; + + } + + /*事件处理器*/ + private void timer_Tick(object sender, EventArgs e) + { + TimeNow = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); + } + /// /// 窗体控制 @@ -150,6 +177,10 @@ namespace SlnMesnac.WPF.ViewModel _logger.LogError("界面跳转逻辑异常", ex); } } + + + + } }