Over a million developers have joined DZone.

How To Override The Default Color Of A ProgressBar In A Windows 8 Application

DZone's Guide to

How To Override The Default Color Of A ProgressBar In A Windows 8 Application

· Mobile Zone ·
Free Resource

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 x:Key="Default">
        <x:String x:Key="ProgressBarIndeterminateForegroundThemeBrush">White</x:String>

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!


Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}