绑定到WPF中的元素:路径表达式是否可以数学? [英] Binding to element in WPF: can the Path expression do math?
本文介绍了绑定到WPF中的元素:路径表达式是否可以数学?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试使用 ElementName
和路径将控件绑定到父级的Height / width属性。但是,我不想绑定到实际的高度,而是要达到一半的高度。
可以路径
表达式做数学吗?
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?
Path = {ActualHeight / 2}
我找不到办法。有没有其他聪明的方法?
I couldn't find a way to do that. IS there any other clever approach?
谢谢!
推荐答案
否你不应该使用绑定转换器
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中的元素:路径表达式是否可以数学?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文