DispatcherTimer 应用实例

 1     public partial class MainWindow : Window
 2     {
 3         public MainWindow()
 4         {
 5             InitializeComponent();
 6             //实例化
 7             DispatcherTimer dis = new DispatcherTimer() 
 8             {
 9                 Interval = TimeSpan.FromMilliseconds(10)
10             };
11             dis.Tick += dis_Tick;//写完+=之后按两下Tab可自动创建void dis_Tick(object sender, EventArgs e)
12             dis.Start();//dis.Stop();
13         }
14         double ProgressValue = 0;
15         void dis_Tick(object sender, EventArgs e)
16         {
17             if (ProgressValue <= myCan.Width)
18             {
19                 myBorder.Width = ProgressValue++;
20             }
21             else
22             {
23                 ProgressValue = 0;
24             }
25         }
26     }
 1 <Window x:Class="ProgressMask.MainWindow"
 2         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 3         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 4         Title="MainWindow" Height="350" Width="525">
 5     <Grid>       
 6         <Canvas Name="myCan" Height="50" Width="500" Background="LightGray">
 7             <Border Name="myBorder" Background="Green" Height="50" Panel.ZIndex="10" Width="10"></Border>
 8         </Canvas> 
 9     </Grid>
10 </Window>
原文地址:https://www.cnblogs.com/yanxh/p/9968112.html