第一步,新建一个转换器
public class CornerConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null)
return DependencyProperty.UnsetValue;
else
return (int)value / 2;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return DependencyProperty.UnsetValue;
}
}
第二步,将转换器定义到XAML页面
<Window.Resources>
<Converter:CornerConverter x:Key="CornerConverter"/>
</Window.Resources>
第三步,在适当的位置使用它
CornerRadius="{Binding ElementName=_border,Path=Height,Converter={StaticResource CornerConverter}}"