Wpf 样式覆盖

Wpf 样式覆盖,wpf,xaml,styles,Wpf,Xaml,Styles,我已经为我的按钮编写了一种新样式(宽度、高度、对齐方式),但我也使用ExpressionDark样式,当我使用我的样式时,例如: <Style x:Key="MyButtonStyle" TargetType="{x:Type Button}"> ... <Button Style="{StaticResource MyButtonStyle}" /> ... 。。。它覆盖了ExpressionDark样式:/p如何避免这种情况?=“{StaticResource{

我已经为我的按钮编写了一种新样式(宽度、高度、对齐方式),但我也使用ExpressionDark样式,当我使用我的样式时,例如:

<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">
...
<Button Style="{StaticResource MyButtonStyle}" />

...
。。。它覆盖了ExpressionDark样式:/p如何避免这种情况?

=“{StaticResource{x:Type Button}}”
您可以使用该属性从现有样式进行扩展

 <Style x:Key="Style1">
   <Setter Property="Control.Background" Value="Yellow"/>
 </Style>

 <Style x:Key="Style2" BasedOn="{StaticResource Style1}">
    <Setter Property="Control.Foreground" Value="Blue"/>
 </Style>


@Nickon:你什么时候设置主题?这应该通过引用按钮的全局隐式样式将您的样式建立在主题样式的基础上。在应用程序中的App.xaml中。参考资料我有以下两行:@Nickon:对我来说,这听起来相当静态,所以我希望StaticResource选择主题样式。它不适合我,不知道为什么(我在写这篇文章之前就用过)