[英]How to update multibinding manually
I had a problem with the Binding
. 我遇到了Binding
问题。 The Rectangle.Fill
dependency property was bound to an ObservableCollection
with the converter. Rectangle.Fill
依赖项属性与转换器绑定到ObservableCollection
。 Although the ObservableCollection
implements INotifyCollectionChanged
, the binding was not updated. 虽然ObservableCollection
实现了INotifyCollectionChanged
,但绑定未更新。 I managed, however, to solve this by attaching my delegation to the collection's change notification event and refreshing the binding manually: 但是,我设法通过将我的代表团附加到集合的更改通知事件并手动刷新绑定来解决此问题:
void ColorsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
BindingExpression b = colorRectangle.GetBindingExpression(Rectangle.FillProperty);
if (b != null)
b.UpdateTarget();
}
Lately, however, I changed the Binding
to MultiBinding
, and the above solution stopped working (the b
is null
). 然而,最近,我将Binding
更改为MultiBinding
,并且上述解决方案停止工作( b
为null
)。 Is there a way to force the Multibinding
to update the target property? 有没有办法强制Multibinding
更新目标属性?
Best regards -- Spook. 最好的问候 - 幽灵。
For a multibinding, the binding expression is a MultiBindingExpression
, which inherits from BindingExpressionBase
, but not from BindingExpression
. 对于多绑定,绑定表达式是MultiBindingExpression
,它继承自BindingExpressionBase
,但不是来自BindingExpression
。 So GetBindingExpression
returns null for a multibinding. 因此, GetBindingExpression
为多重绑定返回null。 Instead you can use BindingOperations.GetMultiBindingExpression
: 相反,您可以使用BindingOperations.GetMultiBindingExpression
:
MultiBindingExpression b = BindingOperations.GetMultiBindingExpression(colorRectangle, Rectangle.FillProperty);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.