你可以绑定一个DataTrigger一个附加属性? [英] Can you bind a DataTrigger to an Attached Property?
问题描述
在WPF中,有可能是一个DataTrigger绑定到一个附加属性?
In WPF, is it possible for a DataTrigger to bind to an attached property?
我基本上是想用一个转换器上的附加属性提供了风格当一个特定的验证规则已被打破。我使用的标记类似如下:
I essentially want to use a converter on an attached property to provide a style when a particular validation rule has been broken. I am using markup like the following:
<DataTrigger Binding="{Binding Path=Validation.Errors,
RelativeSource={RelativeSource Self},
Converter={StaticResource RequiredToBoolConverter}}"
Value="True">
<Setter Property="Background" Value="LightGreen" />
</DataTrigger>
然而,当这个运行时,我得到如下:
However, when this runs, I get the following:
System.Windows.Data错误:39:
BindingEx pression路径错误:
验证属性没有发现
'对象'''文本框'(名称='')。
BindingEx pression:路径= Validation.Errors;
的DataItem ='文本框'(名称='');目标
元素是'文本框'(名称='');目标
属性是'NoTarget'(类型'对象')
System.Windows.Data Error: 39 : BindingExpression path error: 'Validation' property not found on 'object' ''TextBox' (Name='')'. BindingExpression:Path=Validation.Errors; DataItem='TextBox' (Name=''); target element is 'TextBox' (Name=''); target property is 'NoTarget' (type 'Object')
如果我改变我的DataTrigger约束力的路径文本,我没有得到的数据绑定错误(但当然它并没有提供我要求的行为)。
If I change my DataTrigger binding path to "Text", I do not get the databinding error (but of course it does not provide the behaviour I am seeking).
推荐答案
您需要包装的财产在括号:
You need to wrap the property in parentheses:
<DataTrigger Binding="{Binding Path=(Validation.Errors),...
这篇关于你可以绑定一个DataTrigger一个附加属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!