Freigeben über


How to: Create a ProgressBar

Typically ProgressBar controls are used to indicate to the user that a lengthy operation is happening and is not hung. Often ProgressBar controls are implemented inside StatusBar controls. This example implements a ProgressBar inside a StatusBar. The StatusBar is created in Extensible Application Markup Language (XAML) and the ProgressBar in C#. The following example shows how to create the ProgressBar and simulate the progress of an operation using animation.

Example

<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);

For the complete sample see.ProgressBar Sample.

See Also

Other Resources

StatusBar Sample