A progress bar is used here to show
Previous section code:
1<window x:class="Timertest.mainwindow"2xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"3xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"4title="MainWindow"height=" -"Width="525">5<Grid>6<button content="Button"Horizontalalignment=" Left"margin="241,249,0,0"Verticalalignment="Top"Width=" the"click="Button_Click"/>7<progressbar x:name="PB"minimum="0"maximum=" -"Horizontalalignment=" Left"height=" the"margin="10,151,0,0"Verticalalignment="Top"Width="497"/>8 9</Grid>Ten</Window>
View Code
Background code:
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingSystem.Windows;7 usingSystem.Windows.Controls;8 usingSystem.Windows.Data;9 usingSystem.Windows.Documents;Ten usingSystem.Windows.Input; One usingSystem.Windows.Media; A usingSystem.Windows.Media.Imaging; - usingSystem.Windows.Navigation; - usingSystem.Windows.Shapes; the usingSystem.Windows.Threading; - - namespacetimertest - { + /// <summary> - ///Interaction logic for MainWindow.xaml + /// </summary> A Public Partial classMainwindow:window at { - PublicMainWindow () - { - InitializeComponent (); - } - in Private voidButton_Click (Objectsender, RoutedEventArgs e) - { toDispatcherTimer DispatcherTimer =NewDispatcherTimer (); +Dispatchertimer.tick + =NewEventHandler (Dispatchertimer_tick); -Dispatchertimer.interval =NewTimeSpan (0,0,1); the Dispatchertimer.start (); * } $ Panax Notoginseng Private voidDispatchertimer_tick (Objectsender, EventArgs e) - { thePb. Value + =3; + } A } the}View Code
WPF's use of System.Windows.Threading.DispatcherTimer (repeat doing something every once in a while)