Windows.UI.Xaml.Controls.ProgressBar

November 30, 2023 · View on GitHub

-description

Represents a control that indicates the progress of an operation, where the typical visual appearance is a bar that animates a filled area as progress continues.

Equivalent WinUI 2 API for UWP: Microsoft.UI.Xaml.Controls.ProgressBar (for WinUI in the Windows App SDK, see the Windows App SDK namespaces).

-xaml-syntax

<ProgressBar .../>

-remarks

Tip

For more info, design guidance, and code examples, see Progress controls.

A ProgressBar control visually indicates progress of an operation with one of two styles: a bar that displays a repeating pattern, or a bar that fills based on a value.

Indeterminate progress bar control Progress bar control

The IsIndeterminate property determines the appearance of a ProgressBar.

Control style and template

You can modify the default Style and ControlTemplate to give the control a unique appearance. For information about modifying a control's style and template, see Styling controls. The default style, template, and resources that define the look of the control are included in the generic.xaml file. For design purposes, generic.xaml is available locally with the SDK or NuGet package installation.

  • WinUI Styles (recommended): Use Microsoft.UI.Xaml.Controls.ProgressBar.
  • Non-WinUI styles: For built-in styles, see %ProgramFiles(x86)%\Windows Kits\10\DesignTime\CommonConfiguration\Neutral\UAP\<SDK version>\Generic\generic.xaml.

Locations might be different if you customized the installation. Styles and resources from different versions of the SDK might have different values.

XAML also includes resources that you can use to modify the colors of a control in different visual states without modifying the control template. Modifying these resources is preferred to setting properties such as Background and Foreground. For more info, see the Light-weight styling section of the XAML styles article. Light-weight styling resources are available starting in Windows 10, version 1607 (SDK 14393).

Notes for previous versions

Windows 8.x In an app compiled for Windows 8, when the ProgressBar is indeterminate, the progress animation continues even if it's not visible on the screen, such as when the ProgressBar Visibility is Collapsed. This can keep the UI thread awake, use resources, and impair app performance. When the ProgressBar is not visible, you should disable the animation by setting IsIndeterminate to false.

-examples

Tip

For more info, design guidance, and code examples, see Progress controls.

If you have the WinUI 2 Gallery app installed, click here to open the app and see the ProgressBar in action.

The following example demonstrates a value-based ProgressBar and an indeterminate ProgressBar.

<StackPanel x:Name="LayoutRoot">
    <StackPanel BorderBrush="Black" BorderThickness="4" Padding="12">
        <TextBlock Text="Value-Based Progress Bar"/>
        <ProgressBar x:Name="progressBar1" Value="0" Maximum="200" Margin="0,12"/>
        <RepeatButton Content="Press and hold" Click="RepeatButton_Click"/>
    </StackPanel>
    <StackPanel BorderThickness="4" BorderBrush="Black" Padding="12">
        <TextBlock Text="Indeterminate Progress Bar"/>
        <ProgressBar IsIndeterminate="True" Margin="0,12"/>
    </StackPanel>
</StackPanel>

private static int _clicks = 0;

private void RepeatButton_Click(object sender, RoutedEventArgs e)
{
    _clicks += 1;
    progressBar1.Value = _clicks;
    if (_clicks >= progressBar1.Maximum) _clicks = 0;
}

-see-also

Progress controls overview, ProgressRing, Controls list