Blue Theme Orange Theme Green Theme Red Theme
 
DevExpress Free UI Controls
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » WPF » WPF ProgressBar

WPF ProgressBar

This tutorial shows you how to create and use a ProgressBar control available in Windows Presentation Foundation (WPF) and XAML.

Author Rank :
Page Views : 84706
Downloads : 1254
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
WPF ProgressBarTutorial.zip
 
 
Team Foundation Server Hosting
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 


This tutorial shows you how to create and use a ProgressBar control available in Windows Presentation Foundation (WPF) and XAML.

Introduction

The ProgressBar tag in XAML represents a WPF ProgressBar control.

 

<ProgressBar></ProgressBar>

 

The Width and Height properties represent the width and the height of a ProgressBar.  The Name property represents the name of the control, which is a unique identifier of a control. The Margin property tells the location of a ProgressBar on the parent control. The HorizontalAlignment and VerticalAlignment properties are used to set horizontal and vertical alignments.

 

The following code snippet sets the name, height, and width of a ListView control.  The code also sets horizontal alignment to left and vertical alignment to top.

 

  <ProgressBar Margin="10,10,0,13" Name="ListView1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="300" Height="30" />

 

The progress bar looks like Figure 1.

 

Figure 1.

 

Setting up ProgressBar Value

The Value property of ProgressBar sets up the current value of a ProgressBar control. In the following code, I set the Value property to 60 and now ProgressBar looks like Figure 2.

 

<ProgressBar Margin="10,10,0,13" Name="PBar" HorizontalAlignment="Left"

                 VerticalAlignment="Top" Width="300" Height="30" Value="60" >           

        </ProgressBar>

 

Figure 2.

Dynamically Setting a ProgressBar Value

We can use a Timer or animation to set a ProgressBar value dynamically. The following code creates a DoubleAnimation object and sets ProgressBar.Value by using the ProgressBar.BeginAnimation method.

private void Window_Loaded(object sender, RoutedEventArgs e)

{

    Duration duration = new Duration(TimeSpan.FromSeconds(20));

    DoubleAnimation doubleanimation = new DoubleAnimation(200.0, duration);

    PBar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);

}

If you run the application, the ProgressBar run look like Figure 3.

Figure 3.

 

Flow Direction

The FlowDirection property sets the flow of ProgressBar. You can set this value either LeftToRight or RightToLeft. The default value is LeftToRight.

FlowDirection="RightToLeft"

Adding a ProgressBar to a StatusBar

You probably saw several applications like Internet Explorer where you can see the status of a page load in the status bar at the bottom by using a ProgressBar looks like Figure 4.

Figure 4.

The following code adds a StatusBar to WPF using XAML.

<StatusBar Name="SBar" Grid.Column="0" Grid.Row="5" VerticalAlignment="Bottom" Background="LightBlue"  >

    <StatusBarItem>

        <TextBlock>Status:</TextBlock>

    </StatusBarItem>

</StatusBar>

The following code creates a ProgressBar dynamically and adds it to the StatusBar and sets the duration for changing the value of the ProgressBar.

private void CreateDynamicProgressBarControl()

{

    ProgressBar PBar2 = new ProgressBar();

    PBar2.IsIndeterminate = false;

    PBar2.Orientation = Orientation.Horizontal;

    PBar2.Width = 200;

    PBar2.Height = 20;

    Duration duration = new Duration(TimeSpan.FromSeconds(20));

    DoubleAnimation doubleanimation = new DoubleAnimation(200.0, duration);

    PBar2.BeginAnimation(ProgressBar.ValueProperty, doubleanimation);

    SBar.Items.Add(PBar2);

} 

 

Summary

In this article, I discussed how to create and use a ProgressBar control available in WPF. 

 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 Article Extensions
Contents added by matsolof on Sep 29, 2010
I tried using this code but it didn't work. Instead, I got the error message "type or namespace could not be found". I'm rather new to C#, but I think this means you have to add a using statement. I have no clue what to add after "using", though. Searched the internet but found nothing useful.
 [Top] Rate this article
 
 About the author
 
Mahesh Chand
Mahesh is the founder of C# Corner and Mindcracker Network, an author of several .NET programming books and a Microsoft MVP for 6 consecutive years. In his day to day work, Mahesh is a Senior Software Consultant with over 14 years of IT industry experience building systems for Financial and Banking, Engineering & Architectural, Imaging, Construction, Biological & Pharmaceuticals, Healthcare and Education industries. His expertise is Windows Forms, ASP.NET, Silverlight, WPF, WCF, Visual Studio 2010, SQL Server, and Oracle.  If you are looking for a Sharepoint, Windows Forms, ASP.NET, WPF, Silverlight, C#, VB.NET, Oracle, and SQL Server Consultant in Philadelphia area or remote location, drop me a line at MAHESH [AT] C-SHARPCORNER [DOT] COM.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the Top 5 .NET Memory Management Fundamentals
To write the best .NET code, you need to know exactly how the .NET framework really manages memory. Ricky Leeks presents the Top 5 fundamental facts of .NET memory management. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
DevExpress Free UI Controls
Become a Sponsor
 Comments
Hi mahesh by Bechir On August 15, 2008
The new WPF technology is splendid but I still miss the MDI forms
Reply | Email | Modify 
Hi mahesh by Bechir On August 15, 2008
The new WPF technology is splendid but I still miss the MDI forms
Reply | Email | Modify 
Hi mahesh by Bechir On August 15, 2008
The new WPF technology is splendid but I still miss the MDI forms
Reply | Email | Modify 
Hi mahesh by Bechir On August 15, 2008
The new WPF technology is splendid but I still miss the MDI forms
Reply | Email | Modify 
Re: Hi mahesh by Mahesh On June 20, 2009
You can still build MDI forms in WPF. Actually, MSDN has a sample project that is very complex similar to Visual Studio IDE with multiple MDI forms.
Reply | Email | Modify 
extern Progress bar ..I need Help by Mohamed On June 26, 2009
Thank you Mahesh
but I want to control this progress bar  by anther .cs
progress bar in WPF --->internal System.Windows.Controls.ProgressBar PBar;
but i want to convert it into extern this is invalid
could you help me please
thanks in advance

Reply | Email | Modify 
Re: extern Progress bar ..I need Help by Mahesh On June 30, 2009
Define it public and you should be able to access it.
Reply | Email | Modify 
ValueProperty by Abbott On October 3, 2009
My ProgressBar does not expose ValueProperty, only Value. Is there atrick to the definition?
Abbott
Reply | Email | Modify 
FOund ValueProperty by Abbott On October 3, 2009
Sorry about the last post. I was looking in the created ProgressBar object, not the control definition.
Tnx
Reply | Email | Modify 
progress bar with webBrowser control by zafi On November 12, 2009
Thank you Mahesh for this article.

I have a web browser control on my form and I want to associate a progress bar to that control. i.e. until the site in it opens, the progress bar should show the status. Can you please suggest me how I can do that? Thanks in advance
Reply | Email | Modify 
great post by ankara On September 28, 2010
great post dude
Reply | Email | Modify 
width of the progress bar by Roshini On January 6, 2011
hey is it possible to also control the width of the progress bar.. i want increase and decrease the width of the bar along with the increase and decrease in values dynamically. is that possible?
Reply | Email | Modify 
WPF ProgressDialog by Jürgen On June 18, 2011
Great article! Here you find another nice article about how to implement a WPF progress dialog: http://www.parago.de/2011/04/how-to-implement-a-modern-progress-dialog-for-wpf-applications/
Reply | Email | Modify 
A Progress Bar using WPF’s ProgressBar Control, BackgroundWorker, and MVVM by Jared On August 26, 2011
I wrote an article that takes this to the next step. <a href="http://www.rhyous.com/2010/12/29/a-progress-bar-using-wpfs-progress-bar-control-backgroundworker-and-mvvm/">A Progress Bar using WPF’s ProgressBar Control, BackgroundWorker, and MVVM</a> For those who need MVVM and for the item tracking progress to run in the background, this is is a good complement to your article.
Reply | Email | Modify 
A Progress Bar using WPF’s ProgressBar Control, BackgroundWorker, and MVVM by Jared On August 26, 2011
I wrote an article that takes this to the next step. <a href="http://www.rhyous.com/2010/12/29/a-progress-bar-using-wpfs-progress-bar-control-backgroundworker-and-mvvm/">A Progress Bar using WPF’s ProgressBar Control, BackgroundWorker, and MVVM</a> For those who need MVVM and for the item tracking progress to run in the background, this is is a good complement to your article.
Reply | Email | Modify 
wpf progress bar by gene On September 23, 2011
I implemented the code above and the progress bar does not look like it does in the illustration. It has the block style instead of continuous. Is there an easy way to set the style to continuous like there is in windows.forms progrsss bars? I've been hunting around and haven't been able to find anything. Thanks.
Reply | Email | Modify 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.