添加时间

dev_yang
杨威 7 months ago
parent dff59c1f27
commit 572cd4d851

@ -44,7 +44,7 @@
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Border Grid.Column="0">
<Label Content="yyyy-MM-dd-HH-mm" FontSize="21" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,8"/>
<Label Content="{Binding TimeNow}" Name="NowTime" FontSize="21" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,0,8"/>
</Border>
<Border Grid.Column="1">

@ -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
}
}

@ -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 参数定义
/// <summary>
@ -88,7 +96,26 @@ namespace SlnMesnac.WPF.ViewModel
ControlOnClickCommand = new RelayCommand<object>(obj => ControlOnClick(obj));
FormControlCommand = new RelayCommand<object>(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");
}
/// <summary>
/// 窗体控制
@ -150,6 +177,10 @@ namespace SlnMesnac.WPF.ViewModel
_logger.LogError("界面跳转逻辑异常", ex);
}
}
}
}

Loading…
Cancel
Save