WPF border圆角CornerRadius的绑定

错误写法:

public Thickness Radius
{
get { return (Thickness)GetValue(RadiusProperty); }
set { SetValue(RadiusProperty, value); }
}
public static readonly DependencyProperty RadiusProperty =
DependencyProperty.Register("Radius", typeof(Thickness), typeof(CheckButton), new PropertyMetadata(new Thickness(0)));

正确写法

public string Radius
{
get { return (string)GetValue(RadiusProperty); }
set { SetValue(RadiusProperty, value); }
}
public static readonly DependencyProperty RadiusProperty =
DependencyProperty.Register("Radius", typeof(string), typeof(CheckButton), new PropertyMetadata("0"));

前台border

<Border BorderBrush="#31669A" CornerRadius="{Binding Radius}" Background="#31669A" BorderThickness="1"  />

搞不太懂为什么要用string而不是Thickness

posted @ 2021-09-01 08:47  奇迹之耀  阅读(332)  评论(0编辑  收藏  举报