覆盖WPF中的主题

nab*_*rid 5 wpf xaml themes styles

我正在处理的wpf项目有一个小问题.我是WPF的新手.在我的app.xaml中,我正在为我的应用程序使用Microsoft Aero主题.我的app.xaml中有类似的东西

 <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/PresentationFramework.Aero;V3.0.0.0;31bf3856ad364e35;component/themes/Aero.NormalColor.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

现在我想知道如何覆盖某些样式属性,例如For Buttons我想要覆盖字体样式,同时保留其余的aero样式.

如果我在窗口资源中为按钮定义样式,例如

 <Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}" x:Key="RedTextBasedOnButton">
            <Setter Property="Foreground" Value="Red" />
        </Style>
Run Code Online (Sandbox Code Playgroud)

并根据上述样式定义一个按钮

该按钮会丢失所有的航空风格属性.我认为问题与我为样式定义BasedOn属性的方式有关

BasedOn="{StaticResource {x:Type Button}}"
Run Code Online (Sandbox Code Playgroud)

我不认为资源是静态的,因为它来自一个DLL,它可能应该是这样的.不过不确定.

BasedOn="{DynamicResource {x:Type Button}}"
Run Code Online (Sandbox Code Playgroud)

但上面引发了异常,如果我在app.xaml中有多个resourcedictionary,例如luna和classic.如何判断哪一个用作默认值,同时使用和覆盖另一个(例如luna)专门用于我的ui中的某些控件?所以我的一些按钮将基于luna风格,而一些按照航空风格进行一些进一步修改?

任何的想法?

问候,

Nat*_*Tay 0

对于您的具体问题

例如,对于按钮,我想覆盖字体样式,同时保留其余的航空样式。

我会尝试将其添加到您的资源词典中:

<FontFamily x:Key="YourFont">Tahoma</FontFamily>
Run Code Online (Sandbox Code Playgroud)

然后在您的样式中使用它:

<Style TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}" x:Key="RedTextBasedOnButton">
     <Setter Property="FontFamily" Value="{StaticResource YourFont}"/>
</Style>
Run Code Online (Sandbox Code Playgroud)

因此,您可以根据一个键更改 FontFamily。

我建议查看此http://wpfthemes.codeplex.com/SourceControl/latest#WPF.Themes.Demo/Window1.xaml