Recently do a project, see previous colleagues write progress bar effect is good, so, to simplify the next, not dazzle, but the project is enough.
Or, first of all, look at the effect of downward use.
1, because the Progressbbar foreground display has to be the same, so, to have a parameter to set the control, so defined a parameter value 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; }}
The code has such a word "LinearGradientBrush LGB = dictionary[" Foregroundcolor "+ value] as LinearGradientBrush;" is to facilitate the use of this parameter to the style file to take the style.
<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, since it is progressbar to have a progress value, this value, we use TextBlock to display, we must implement the notification interface, in order to ensure real-time notification to the page.
public string Valuetext{get{return _valuetext; } set{ _valuetext = Value;if (this. propertychanged = null) {this. Propertychanged.invoke (This, new PropertyChangedEventArgs ("ValueText"));}}}
3, enable a background thread, to constantly update the progress effect
private void Bgw_dowork (object sender, DoWorkEventArgs e) {for (int i = 0; i < barvalue; i++) { system.threading . Thread.Sleep (+); ProBar.Dispatcher.Invoke (New Action ( delegate{if (probar.value <= barvalue) { probar.value++; } })); ValueText = i + ""; } ValueText = Barvalue + "";}
Source