如何将某些东西绑定到Path值的一小部分? Path = ActualPath / 2似乎不起作用。
Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type UserControl}},
Path=ActualHeight / 2}">
答案 0 :(得分:3)
您可以使用ValueConverter执行此操作,例如:
class MakeHalfConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((double)value)/2;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((double)value)*2;
}
}
答案 1 :(得分:1)
没有开箱即用。您需要使用值转换器。
查看几个即用型转换器here。您可以使用ExpressionConverter
作为您的方案。