你能通过WPF样式数据绑定到CornerRadius吗?

Geo*_*Cox 2 data-binding wpf styles cornerradius

我有一个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>
Run Code Online (Sandbox Code Playgroud)

两者和CornerRadius ="{TemplateBinding CornerRadius}"给我错误"CornerRadius无法识别或无法访问".

Ken*_*art 5

您正在尝试CornerRadius在类上设置/绑定属性Button,但是没有这样的属性.所以错误是预期的.