You're not limited to the dependency properties of the control you're templating. In this case, while Button
does not have a CornerRadius
property, Border
does, so you can use Border.CornerRadius
instead:
<Style TargetType="Button" x:Key="TabButton">
<Setter Property="Background" Value="White" />
<Setter Property="TextBlock.TextAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border CornerRadius="{TemplateBinding Border.CornerRadius}"
Background="White" BorderBrush="#ccc"
BorderThickness="0,1,1,0" >
<ContentPresenter x:Name="contentPresenter"
ContentTemplate="{TemplateBinding ContentTemplate}"
Content="{TemplateBinding Content}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="Button" x:Key="TabButtonFirst" BasedOn="{StaticResource TabButton}">
<Setter Property="Border.CornerRadius" Value="3,0,0,0" />
</Style>
<Style TargetType="Button" x:Key="TabButtonLast" BasedOn="{StaticResource TabButton}">
<Setter Property="Border.CornerRadius" Value="0,0,0,3" />
</Style>
With this approach, you no longer need to maintain multiple copies of your control template.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…