A progress bar is a control that an application can use to indicate the progress of a lengthy operation. It consists of a rectangle that is gradually filled as an operation progresses. This topic introduces the ProgressBar control and illustrates how to use it in C#.
This topic contains the following sections.
ProgressBar controls are used whenever an operation takes more than a short period of time. The ProgressBar indicates to users that the operation is happening and that the application is not hung. The following graphic shows a typical ProgressBar.
Creating a ProgressBar
The following example shows how to create a ProgressBar. The ProgressBar is contained inside a StatusBar. The StatusBar is implemented in Extensible Application Markup Language (XAML) and the ProgressBar in C#.
<StatusBar Name="sbar" Grid.Column="0" Grid.Row="5" VerticalAlignment="Bottom" Background="Beige" > <StatusBarItem> <TextBlock>StatusBar</TextBlock> </StatusBarItem> </StatusBar>
ProgressBar progbar = new ProgressBar(); progbar.IsIndeterminate = false; progbar.Orientation = Orientation.Horizontal; progbar.Width = 150; progbar.Height = 15; Duration duration = new Duration(TimeSpan.FromSeconds(10)); DoubleAnimation doubleanimation = new DoubleAnimation(100.0, duration); progbar.BeginAnimation(ProgressBar.ValueProperty, doubleanimation); sbar.Items.Add(progbar);
Notice that the progress indicated by the bar is simulated by using an animation.
For the complete sample, see ProgressBar Sample