views:

112

answers:

1

Hi

I'm trying to bind a control to the parent's Height/width property using ElementName and a Path. However, I don't want to bind to the actual height, but to exactly half the height. Can the Path expression do the math?

e.g. Path={ActualHeight/2}

I couldn't find a way to do that. IS there any other clever approach?

Thanks!

+1  A: 

No it can't you should use binding converters

public class MyConverter : IValueConverter
{
public object Convert(object value, Type  targetType,
      object parameter, CultureInfo culture)
  {
      return (int)value/2;
  }

  public object ConvertBack(object value, Type targetType,
      object parameter, CultureInfo culture)
  {
    return null;
  }
}
ArsenMkrt
Value converters exist solely for this purpose - to transform the value between the source and target - http://www.wpftutorial.net/ValueConverters.html. Or if that is too much, you could declare a new get-only property HalfOfActualHeight if that is an option.
Gishu
It seems this is exactly what I need, even if the task is so trivial. Thanks!
John