I had a problem with the Binding
. The Rectangle.Fill
dependency property was bound to an ObservableCollection
with the converter. Although the ObservableCollection
implements INotifyCollectionChanged
, the binding was not updated. 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
). Is there a way to force the Multibinding
to update the target property?
Best regards -- Spook.
For a multibinding, the binding expression is a MultiBindingExpression
, which inherits from BindingExpressionBase
, but not from BindingExpression
. So GetBindingExpression
returns null for a multibinding. Instead you can use BindingOperations.GetMultiBindingExpression
:
MultiBindingExpression b = BindingOperations.GetMultiBindingExpression(colorRectangle, Rectangle.FillProperty);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With