我有一个 Button 样式,似乎无法将边框的 CornerRadius 属性数据绑定到模板。这是一个依赖属性,所以它应该是数据可绑定的。我想知道我是否缺少要使用的正确 XAML 语法?
<Style TargetType="{x:Type Button}" BasedOn="{x:Null}">
<Setter Property="FocusVisualStyle" Value="{DynamicResource MyButtonFocusVisual}"/>
<Setter Property="Background" Value="{DynamicResource MyButtonBackgroundBrush}"/>
<Setter Property="Foreground" Value="{DynamicResource MyButtonForegroundBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource MyButtonBorderBrush}"/>
<Setter Property="BorderThickness" Value="3"/>
<Setter Property="FontFamily" Value="Segoe UI"/>
<Setter Property="FontSize" Value="14" />
<Setter Property="CornerRadius" Value="2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<!-- We use Grid as a root because it is easy to add more elements to customize the button -->
<Grid x:Name="Grid">
<Border x:Name="Border" CornerRadius="{TemplateBinding CornerRadius}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
和 CornerRadius="{TemplateBinding CornerRadius}" 都给我错误“CornerRadius 无法识别或无法访问”。