12-DispatcherTimer控制进度条的显示
来源:互联网 发布:大数据生态圈 编辑:程序博客网 时间:2024/06/16 02:55
using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Animation;using System.Windows.Shapes;using Microsoft.Phone.Controls;using System.Windows.Threading;namespace PhoneApp5{ public partial class MainPage : PhoneApplicationPage { //创建一个DispatcherTimer对象 DispatcherTimer dispatcherTimer = new DispatcherTimer(); // 构造函数 public MainPage() { InitializeComponent(); //设置进度条的时间的间隔 dispatcherTimer.Interval = new TimeSpan(5000); //tick事件 dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); } void dispatcherTimer_Tick(object sender, EventArgs e) { progressBar1.Value += 0.1; } private void button1_Click(object sender, RoutedEventArgs e) { dispatcherTimer.Start(); } /** * 点击关闭计时器的方法 */ private void button2_Click(object sender, RoutedEventArgs e) { dispatcherTimer.Stop(); } }}