我有一個按鈕樣式,似乎無法將邊框的CornerRadius屬性綁定到模板。這是一個依賴屬性,所以它應該是數據綁定的。我想知道我是否錯過了使用正確的XAML語法?你可以通過WPF樣式將數據綁定到CornerRadius嗎?
<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無法識別或無法訪問」。
WAG here ... {TemplateBinding Button.CornerRadius} – Will 2008-11-29 20:04:09