In WPF, how to I bind to a fraction of a property?
How do I bind something to a fraction of a Path value? Path=ActualPath/2 does not seem to work.
Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type U开发者_如何学运维serControl}},
Path=ActualHeight / 2}">
You can do that using a ValueConverter, for example:
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;
}
}
Not out of the box. You need to use a value converter for this.
Have a look here for several ready to use converters. You can use the ExpressionConverter
for your scenario.
精彩评论