How to override the default color of a ProgressBar in a Windows 8 application

So you’re doing Windows 8 development and, very likely, your app needs to display some data. Rarely this data is immediately available: maybe you need to download it, or you have to parse it before displaying it. Here comes in help the ProgressBar, so that the user is aware that something is loading and that he needs to wait until the operation is completed.

By default, the ProgressBar automatically uses the accent color the user has selected for his Windows 8 installation: this isn’t always the best choice, because your application may use a background that doesn’t fit with the ProgressBar color.

The first thing you would try to do, as a developer, is to change the Foreground or the Background property of the control, but you’ll notice that the trick doesn’t work: the color of the ProgressBar doesn’t change.

This happens because the default ProgressBar color is defined in one of the default styles, so you have to override it to change it. To do this, simply add the following statement in the ApplicationResources defined in the App.xaml file:

<ResourceDictionary.ThemeDictionaries>
    <ResourceDictionary x:Key="Default">
        <x:String x:Key="ProgressBarIndeterminateForegroundThemeBrush">White</x:String>
    </ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>

In this example, the ProgressBar is displayed with a white color: instead of writing the color’s name, you can also put the hexadecimal code of the color.

Enjoy it!

This entry was posted in Windows 8 and tagged . Bookmark the permalink.

2 Responses to How to override the default color of a ProgressBar in a Windows 8 application

  1. Sruesh says:

    Thanks a lot!

  2. Carrol says:

    Good article! We will be linking to this particularly great post on our website.
    Keep up the good writing.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.