场景:样式A和样式B的背景颜色一样,但是文字颜色不一样
<Style x:key="BaseStyle" TargetType="Button"> <Setter Property="Background" Value="White"> </Style> <Style x:key="RedStyle" BaseOn="{StaticResource BaseStyle}" TargetType="Button"> <Setter Property="Foreground" Value="Red" /> </Style> <Style x:key="BludStyle" BaseOn="{StaticResource BaseStyle}" TargetType="Button"> <Setter Property="Foreground" Value="Blue" /> </Style>
<!-- 如果不指定Target,设置Property时需要使用Control. --> <Style x:key="BaseTyle"> <Setter Property="Control.Background" value="Black" /> </Style>
<Style x:key="RedStyle" BaseOn="{StaticResource BaseStyle}" TargetType="Button"> <Setter Property="Foreground" Value="Red" /> </Style> <Style x:key="BludStyle" BaseOn="{StaticResource BaseStyle}" TargetType="TextBox"> <Setter Property="Foreground" Value="Blue" /> </Style>
<!-- 继承基础样式 --> <Style TargetType="TextBlock" BasedOn="{StaticResource {x:Type TextBlock}}">