我为我的按钮(宽度、高度、对齐方式)编写了一种新样式,但我也使用 ExpressionDark 样式,并且当我使用 MY 样式时,例如:
<Style x:Key="MyButtonStyle" TargetType="{x:Type Button}">
...
<Button Style="{StaticResource MyButtonStyle}" />
...它覆盖了 ExpressionDark 样式:/如何避免这种情况?
BasedOn
="{StaticResource {x:Type Button}}"
您可以使用BasedOn属性来扩展现有样式。
<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>