WPF中实现实时更新progressbar

WPF中实现实时更新progressbar
转自:http://www.ejutuo.com/bbs/thread-3168-1-1.html

      实现实时更新ProgressBar貌似有很多方法,我搜索的很多资料都要用线程,觉得还是有点儿麻烦,最后在国外的技术论坛上看到

  一个用代理解决的方法,下面就是我的调试过程:

普通浏览 复制代码
  1. private  delegate  void UpdateProgressBarDelegate ( System.Windows.DependencyProperty dp,</font></font></font></font></p>
  2. Object value ) ;
  3. private  void Process ( )
  4. {
  5. //Configure the ProgressBar
  6. ProgressBar1.Minimum =  0 ;
  7. ProgressBar1.Maximum =  short.MaxValue ;
  8. ProgressBar1.Value =  0 ;
  9. //Stores the value of the ProgressBar
  10. double value =  0 ;
  11. UpdateProgressBarDelegate updatePbDelegate =  new UpdateProgressBarDelegate (ProgressBar1.SetValue ) ;
  12. //Tight Loop: Loop until the ProgressBar.Value reaches the max
  13. do
  14. {
  15. }
  16. while  (ProgressBar1.Value != ProgressBar1.Maximum ) ;
  17. }
  18.  
前台:
普通浏览 复制代码
  1. <ProgressBar Grid.Row= "1" Height= "20" Width= "200" Margin= "0,4,0,0"   Name= "ProgressBar1" HorizontalAlignment= "Center"  VerticalAlignment= "top"  />
效果:

方法二:使用定时器

普通浏览 复制代码
  1.   public Window1 ( )</font></font></font></font></p>        {
  2.             InitializeComponent ( ) ;
  3.             DispatcherTimer _mainTimer =  new DispatcherTimer ( ) ;
  4.             _mainTimer.Interval = TimeSpan.FromSeconds ( 1 ) ;
  5.             _mainTimer.Tick +=  new EventHandler (_mainTimer_Tick ) ;
  6.             _mainTimer.IsEnabled =  true ;
  7.         }
普通浏览 复制代码
  1. void _mainTimer_Tick ( object sender, EventArgs e )
  2.         {
  3.              if  (progressBar1.Value == progressBar1.Maximum )
  4.                 progressBar1.Value =  0 ;
  5.             progressBar2.Value++ ;
  6.         }


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值