wpf即时显示时间

 

前台定义一个 TextBolck

 

         

后台:

private DispatcherTimer timer;

IntialLoad()

{

           timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();

}

 

void timer_Tick(object sender, EventArgs e)
        {
      
            TextProperty1 = DateTime.Now.ToString();
        }

你可能感兴趣的:(WPF)