开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜