使用绑定的DataTrigger条件的Value属性 [英] Using binding for the Value property of DataTrigger condition

查看:1089
本文介绍了使用绑定的DataTrigger条件的Value属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个WPF应用程序和数据的触发挣扎。我想的触发条件的值绑定到某个对象,我有:

 < D​​ataTrigger绑定={结合美孚}
             值={结合的ElementName = AnotherElement,路径=酒吧}> ..
 

但是,我不能,因为它似乎并不可能使用Value属性绑定。是吗?我能做到这一点不知?我得到以下错误:

  

一个'绑定'不能在类型为DataTrigger的值属性设置。 A'绑定'只能在DependencyObject的一个DependencyProperty的设置。

解决方案

没有,那是不可能的。由于错误消息指出,只有依赖属性可以是WPF绑定的目标,DataTrigger.Value不是一个依赖项属性。所以,你将需要分配一个实际值。

解决方法是使用一个MultiBinding其子绑定,你要比较的两个绑定,与IMultiValueConverter如果两个输入是平等的,假的,如果他们不相等返回true。然后,DataTrigger可以使用该MultiBinding,和值true。

I'm working on a WPF application and struggling with a data trigger. I'd like to bind the value of the trigger condition to some object I have:

<DataTrigger Binding="{Binding Foo}" 
             Value="{Binding ElementName=AnotherElement, Path=Bar}">..

However, I'm not allowed as it doesn't seem to be possible to use bindings for the Value property. Is it? Can I achieve this somehow? I get the following error:

A 'Binding' cannot be set on the 'Value' property of type 'DataTrigger'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

解决方案

No, it is not possible. As the error message says, only dependency properties can be targets of WPF bindings, and DataTrigger.Value is not a dependency property. So you will need to assign an actual value.

The workaround is to use a MultiBinding whose child Bindings are the two bindings you want to compare, with an IMultiValueConverter which returns true if the two inputs are equal and false if they are unequal. The DataTrigger can then use that MultiBinding, and a Value of True.

这篇关于使用绑定的DataTrigger条件的Value属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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