代码之家  ›  专栏  ›  技术社区  ›  Geoff Cox

可以通过WPF样式将数据绑定到CornerRadius吗?

  •  2
  • Geoff Cox  · 技术社区  · 16 年前

    <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无法识别或无法访问”。

    2 回复  |  直到 16 年前
        1
  •  5
  •   Tim Cooper    13 年前

    CornerRadius Button ,但没有这样的属性。因此,错误是意料之中的。

        2
  •  1
  •   Nick    16 年前