本文介绍了绑定路径中的加法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在wpf绑定路径中进行加法运算?
像这样的东西:
Hi,
Is it possible to do addition in wpf binding path?
Something like this:
Width="{Binding ElementName=Grid1, Path=ActualWidth + 20}"
[edit]仅标记-OriginalGriff [/edit]
[edit]Tags only - OriginalGriff[/edit]
推荐答案
[ValueConversion(typeof(double), typeof(double))]
class AddWidthConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
double currentValue = (double)value;
return currentValue + 70;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
然后在Window.Resources中声明转换器,然后像这样在xaml中使用它:
Then declare your converter in your Window.Resources and then use it in your xaml like this :
Width="{Binding ElementName=txtTest, Path=ActualWidth, Converter={StaticResource AddWidth}
这篇关于绑定路径中的加法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!