WPF中实现实时更新progressbar 转自:http://www.ejutuo.com/bbs/thread-3168-1-1.html 实现实时更新ProgressBar貌似有很多方法,我搜索的很多资料都要用线程,觉得还是有点儿麻烦,最后在国外的技术论坛上看到 一个用代理解决的方法,下面就是我的调试过程: 普通浏览 复制代码 private delegate void UpdateProgressBarDelegate ( System.Windows.DependencyProperty dp,</font></font></font></font></p> Object value ) ; private void Process ( ) { //Configure the ProgressBar ProgressBar1.Minimum = 0 ; ProgressBar1.Maximum = short.MaxValue ; ProgressBar1.Value = 0 ; //Stores the value of the ProgressBar double value = 0 ; UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate (ProgressBar1.SetValue ) ; //Tight Loop: Loop until the ProgressBar.Value reaches the max do { } while (ProgressBar1.Value != ProgressBar1.Maximum ) ; } 前台: 普通浏览 复制代码 <ProgressBar Grid.Row= "1" Height= "20" Width= "200" Margin= "0,4,0,0" Name= "ProgressBar1" HorizontalAlignment= "Center" VerticalAlignment= "top" /> 效果: 方法二:使用定时器 普通浏览 复制代码 public Window1 ( )</font></font></font></font></p> { InitializeComponent ( ) ; DispatcherTimer _mainTimer = new DispatcherTimer ( ) ; _mainTimer.Interval = TimeSpan.FromSeconds ( 1 ) ; _mainTimer.Tick += new EventHandler (_mainTimer_Tick ) ; _mainTimer.IsEnabled = true ; } 普通浏览 复制代码 void _mainTimer_Tick ( object sender, EventArgs e ) { if (progressBar1.Value == progressBar1.Maximum ) progressBar1.Value = 0 ; progressBar2.Value++ ; }