The timer control similar to winform is no longer available in WPF. Therefore, you need to use the dispatchertimer class to implement scheduled execution events similar to timer. This event is implemented using delegation. Dispatchertimer classIn
In system. Windows. Threading, the using system. Windows. Threading namespace is required.
Simple ExampleCodeAs follows, the Code displays the current system time in real time in the title of the WPF form.
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. windows; using system. windows. controls; using system. windows. data; using system. windows. documents; using system. windows. input; using system. windows. media; using system. windows. media. imaging; using system. windows. navigation; using system. windows. shapes; using system. windows. threading; namespace timerwindow {// <summary> // interaction logic for mainwindow. XAML /// </Summary> Public partial class mainwindow: window {dispatchertimer timer = new dispatchertimer (); Public mainwindow () {initializecomponent (); timer. tick + = new eventhandler (timer_tick); // timer. interval = timespan. fromseconds (0.1); // set the Refresh Interval timer. start ();} void timer_tick (Object sender, eventargs e) {This. title = string. concat ("timerwindow", datetime. now. tostring ("yyyy-mm-dd hh: mm: SS "));}}}