Windows Store apps开发[45]修改ProgressBar的颜色

来源:互联网 发布:网络推广yes960 编辑:程序博客网 时间:2024/05/22 16:51
当前位置: 银光首页 > Windows 8 > Windows 8学习教程 >


时间:2012-10-21 18:49来源:CSDN 作者:beyondvincent 点击:129次
如果你想要修改ProgressBar的foreground 颜色,用下面的方法是不行的: ProgressBarIsIndeterminate= True Foreground= Aquamarine / 要修改ProgressBar的颜色,需要override默认主题资源字典中的如下值: ResourceDictionary.ThemeDictionaries ResourceDictionaryx:Key= Default x: String x:Key= ProgressBarIndetermin
  

  如果你想要修改ProgressBar的foreground 颜色,用下面的方法是不行的:

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

  要修改ProgressBar的颜色,需要override默认主题资源字典中的如下值:

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

  可以将这个override添加到App.xaml中,或者创建一个新的资源字典,并合并到App.xaml中:

  A、直接添加到App.xaml中,如下代码:

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.ThemeDictionaries>
            <ResourceDictionary x:Key="Default">
                <x:String x:Key="ProgressBarIndeterminateForegroundThemeBrush">Red</x:String>
            </ResourceDictionary>
        </ResourceDictionary.ThemeDictionaries>
        <ResourceDictionary.MergedDictionaries>

            <!-- 
                Styles that define common aspects of the platform look and feel
                Required by Visual Studio project and item templates
                -->
            <ResourceDictionary Source="Common/StandardStyles.xaml"/>
        </ResourceDictionary.MergedDictionaries>

    </ResourceDictionary>
</Application.Resources>

  B、创建了一个CustomStyles.xaml,并将该文件合并到App.xaml中:

<Application
    x:Class=
"Sample.App"
    xmlns=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x=
"http://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=
"http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x=
"http://schemas.microsoft.com/winfx/2006/xaml">
    <!-- Global Overrides -->
    <ResourceDictionary.ThemeDictionaries>
        <ResourceDictionary x:Key="Default">
            <x:String x:Key="ProgressBarIndeterminateForegroundThemeBrush">Red</x:String>
        </ResourceDictionary>
    </ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>