atsjoo
atsjoo

Reputation: 2472

How do I reevaluate all bindings in a multibinding when one of them changes?

I have a setup similar to this:

var binding1 = new Binding($"Item[0].IsChecked")
   {
        Source = sender,
        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
        ConverterParameter = dependant
    };

    var binding2 = new Binding($"Item")
    {
        Source = sender,
        Converter = new AllItemsAreEqualConverter(),
        ConverterParameter = dependant
    };
    var multiBinding = new MultiBinding
    {
        Bindings = { binding1, binding2 }, Converter = unifyingConverter
    };

My model implements INotifyPropertyChanged and changing the IsChecked-property reevaluates binding1 as expected. However in practice by doing so the result of binding2 should also change. However I would also like to reevalute binding2 which is also part of my multibinding. Is it possible to tell the multibinding to reevaluate all sub-bindings when one of them has changed?

Just to add some more context which may or may not be helpful: I am trying to use this behavior in a telerik property grid that edit one or more objects that the same time, and my idea was that by having the first binding gives notification upon PropertyChanged for the IsChecked property, that would reevaluate the state of my binding, and the second binding would check the same property for all of the selected models making up the data set for the binding on the Visibility property of a specific property definition (the "unifyingConverter" refered to in my multibinding translates the values from the two sub bindings in to a Visibility).

Hope this is adequate information to answer my question. Thanks :)

Upvotes: 0

Views: 88

Answers (1)

mm8
mm8

Reputation: 169320

Is it possible to tell the multibinding to reevaluate all sub-bindings when one of them has changed?

It "reevaluates" itself and the converter is invoked. In the Convert method you will then have access to the latest known values of all properties of all bindings that are part of the MultiBinding.

So when the PropertyChanged event is raised for the IsChecked property, the Convert method of the converter is invoked and in this method you can then get the latest value of both IsChecked (values[0]) and Item (values[1]).

For the converter to get invoked for the second property, you need to raise the PropertyChanged event for the Item property itself.

Upvotes: 1

Related Questions