【发布时间】:2018-09-26 09:17:30
【问题描述】:
在我们的项目中,我们有按钮的默认样式,它定义了按钮的模板,并且有一个Border 属性为CornerRadius="0":
<Style TargetType="Button" x:Key="TemplatedButton">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border BorderBrush="{TemplateBinding BorderBrush}"
CornerRadius="0"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
Cursor="{TemplateBinding Cursor}"
>
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
ContentStringFormat="{TemplateBinding ContentStringFormat}"
RecognizesAccessKey="True"
/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Button控件没有CornerRadius属性,因此无法将该属性绑定到TemplateBinding,但是对于某些控件我们需要自定义CornerRadius属性:
<Button Style="{StaticResource TemplatedButton}" x:Name="btn1" Content="Button with radius" /*HERE WE NEED TO SET CUSTOM CornerRadius*/ />
是否有可能以某种方式改变拐角半径?也许是继承它的风格,或者通过向 btn1 添加资源?
我看到可以通过将具有相同键的资源设置为不同的值来自定义默认属性,但不知道如何实现。如果您提供有关如何实现它的任何教程或文档,将不胜感激。
【问题讨论】: