我有 ControlTemplate OrangeButton 的简单样式,并且我创建了另一种样式 OrangeButton2 BasedOn OrangeButton。我正在尝试更改边框属性,但 WPF 不会呈现 OrangeButton2 中定义的新边框样式。我也尝试了相反的方法,OrangeButton 基于 OrangeButton2,没有任何变化。知道这里实际发生了什么,以及如何使它正确。
<Style x:Key="OrangeButton" TargetType="Button" >
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Margin" Value="2"/>
<Setter Property="FontFamily" Value="Verdana"/>
<Setter Property="FontSize" Value="11px"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border Name="border"
BorderThickness="1"
Padding="4,2"
BorderBrush="DarkGray"
CornerRadius="3"
Background="{TemplateBinding Background}">
<Grid >
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" Name="contentShadow" Style="{StaticResource ShadowStyle}">
</ContentPresenter>
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Name="content"/>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="OrangeButton2" TargetType="Button" BasedOn="{StaticResource OrangeButton}">
<Setter Property="BorderBrush" Value="Red"></Setter>
<Setter Property="BorderThickness" Value="1"></Setter>
</Style>
</Window.Resources>
<StackPanel HorizontalAlignment="Center">
<Button Style="{StaticResource OrangeButton2}">Hello</Button>
</StackPanel>