绑定到元素在WPF:可以在路径前pression做数学? [英] Binding to element in WPF: can the Path expression do math?

查看:221
本文介绍了绑定到元素在WPF:可以在路径前pression做数学?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用控制到家长的高度/宽度属性的ElementName 和路径绑定。然而,我不想绑定到的实际高度,而是正好一半的高度。 在路径 EX pression可以做数学题?

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?

例如。 路径= {的ActualHeight / 2}

我无法找到一个方法来做到这一点。是否有任何其他聪明的做法?

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

谢谢!

推荐答案

没有它不能,你应该使用的装订器

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;
  }
}

这篇关于绑定到元素在WPF:可以在路径前pression做数学?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆