How does WPF implement a simple progress bar?

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.