效果:
如图所示
1、首先写一个文本框用来显示时间如下:
2、在后台中,先自定义一个把时间绑定在文本框的方法
3、在外部声明一个计时器的全局变量
4、在页面加载事件写一个定时器方法
页面代码
<Window x:Class="显示时间.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:显示时间