Question

I'd like to use the ItemsSource property from a particular element as one of the bindings in another element's MultiBinding. Here's what I have so far:

<Label>
  <Label.Content>
    <MultiBinding Converter="{converters:myMultiValueConverter}">
      <Binding Path="PageIndex" />
      <Binding ElementName="anotherElement" Path="ItemsSource"/>
    </MultiBinding>
  </Label.Content> 
</Label>

This works once (when the ItemsSource is initially set), but the binding fails to update when the ObservableCollection bound to the original element's ItemsSource property has items added or removed. Is this kind of binding possible?

Was it helpful?

Solution

Add a dummy binding (- you don't need the value -) like this to force the MultiBinding to be reevaluated:

<Binding ElementName="anotherElement" Path="ItemsSource.Count"/>

Edit: Just noticed a flaw: If you move items that would not register if that does not change the Count property in-between, maybe this is relevant for you. In that case you could bind to your own dummy for which you can fire change notifications upon CollectionChanged (not all that clean in any case though).

You might want to consider HighCore's suggestion, a get-only property that returns the calculated value for which you manually fire PropertyChanged in all places that it depends on is usually quite convenient.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top