다음을 통해 공유


Changing the Foreground Color of an Indeterminate ProgressBar

You would think that the following XAML changes the indeterminate progress bar’s foreground color:

 <ProgressBar IsIndeterminate="True" Foreground="Aquamarine" />

Unfortunately, that doesn’t work. You will need to override the following value in the default theme resource dictionary:

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

You can add that override to App.xaml, or to a new resource dictionary that’s merged into App.xaml:

 <Application
    x:Class="Sample.App"
    xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">
    
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Common/StandardStyles.xaml" />
                <ResourceDictionary Source="Common/CustomStyles.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

CustomStyles.xaml:

 <ResourceDictionary
    xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml">
    <!-- Global Overrides -->
    <ResourceDictionary.ThemeDictionaries>
        <ResourceDictionary x:Key="Default">
            <x:String x:Key="ProgressBarIndeterminateForegroundThemeBrush">Aquamarine</x:String>
        </ResourceDictionary>
    </ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>

Comments

  • Anonymous
    November 01, 2012
    It looks like a bug and you just have a workaround. Any reason for such strange behaviour?

  • Anonymous
    November 02, 2012
    Please feel free to file a bug at http://connect.microsoft.com/

  • Anonymous
    December 19, 2012
    Nice trick ! Really strange behaviour compared to the ProgressRing

  • Anonymous
    December 17, 2015
    Very helpful, useful, and clear.  Thank you for this!