WPF Timer Like C# Timer

2019-01-05 09:14发布

Where can I find a control which is like the C# Timer Control in WPF?

标签: c# wpf timer
3条回答
Melony?
2楼-- · 2019-01-05 09:47

you can also use

using System.Timers;
using System.Threading;
查看更多
Bombasti
3楼-- · 2019-01-05 09:49

The usual WPF timer is the DispatcherTimer, which is not a control but used in code. It basically works the same way like the WinForms timer:

System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer();
dispatcherTimer.Tick += dispatcherTimer_Tick;
dispatcherTimer.Interval = new TimeSpan(0,0,1);
dispatcherTimer.Start();


private void dispatcherTimer_Tick(object sender, EventArgs e)
{
  // code goes here
}

More on the DispatcherTimer can be found here

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-01-05 10:02

With Dispatcher you will need to include

using System.Windows.Threading;

Also note that if you right-click DispatcherTimer and click Resolve it should add the appropriate references.

查看更多
登录 后发表回答