最近做一个项目,看到以前同事写的进度条效果不错,所以,拿来简化了下,不炫,但是项目中还是够用的。

还是,先来看下调用以后的效果

1、因为ProgressbBar的Foreground显示不得不一样,所以,要有一个参数去给控件进行设置,因此定义了一个参数值ForegroundColor

public int ForegroundColor{get{return _foregroundColor;    }set{        _foregroundColor = value;        LinearGradientBrush lgb = dictionary["ForegroundColor" + value] as LinearGradientBrush;if (lgb != null)            proBar.Foreground = txt.Foreground = percent.Foreground = lgb;    }}

代码里有这么一句话“LinearGradientBrush lgb = dictionary["ForegroundColor" + value] as LinearGradientBrush;”是为了方便通过这是这个参数去样式文件里取样式的。

<LinearGradientBrush x:Key="ForegroundColor1" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FFBBF586" Offset="0.5"/><GradientStop Color="#FFD4F9C3" Offset="1"/></LinearGradientBrush><LinearGradientBrush x:Key="ForegroundColor2" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FF5BE26E" Offset="0.5"/><GradientStop Color="#FF8DEC9C" Offset="1"/></LinearGradientBrush><LinearGradientBrush x:Key="ForegroundColor3" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FFB656F2" Offset="0.5"/><GradientStop Color="#FFAE8DFE" Offset="1"/></LinearGradientBrush><LinearGradientBrush x:Key="ForegroundColor4" EndPoint="1,0.5" StartPoint="0,0.5"><GradientStop Color="#FF3AE9E9" Offset="0.5"/><GradientStop Color="#FF8DFDFE" Offset="1"/></LinearGradientBrush>

2、既然是ProgressBar就要有一个进度值,这个值,我们用TextBlock来进行显示,一定要实现通知接口,这样,才能保证实时的通知到页面上。

public string ValueText{get{return _valueText;    }set{        _valueText = value;if (this.PropertyChanged != null)        {this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("ValueText"));        }    }}

3、启用一个后台线程,来不断的更新进度效果

private void Bgw_DoWork(object sender, DoWorkEventArgs e){for (int i = 0; i < BarValue; i++)    {        System.Threading.Thread.Sleep(50);        proBar.Dispatcher.Invoke(new Action(                                     delegate{if (proBar.Value <= BarValue)            {                proBar.Value++;            }        }));        ValueText = i + "";    }    ValueText = BarValue + "";}

源码

更多相关文章

  1. angularjs是怎么为ng-click事件传递参数的?
  2. C#中SQL参数传入空值出错误和如何解决办法
  3. 分享一个jQuery效果实例代码
  4. 详解可选参数和命名参数实例
  5. ASP.NET中的参数与特殊类型的实例详解
  6. 详述Entity Framework自定义分页效果实现方法
  7. 利用Dapper实现分页效果方法教程
  8. ASP.NET如何实现进度条效果的实例讲解
  9. Entity Framework自定义分页效果的实现教程

随机推荐

  1. 删除后重新插入后保留对元素的引用
  2. jquery 添加transform样式
  3. Ajaxify在Ruby on Rails 4上的评论发布和
  4. 不玩Android的jQuery jPlayer。
  5. 关于js 方法,实现ajax请求时,return fals
  6. 如何在MVC4中使用type= " url "而不用jQu
  7. jquery.min.js引入项目报错
  8. JQuery攻略(三)数组与字符串
  9. jsf中获取属性值的普通获取和jquery获取
  10. jQuery中filter()和find()的区别深入了解