Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MultiBinding with MultiValueConverter does not update

it seems that I have a problem with my multibinding.

Scenario:
I have a window with two datepickers and a listview. The listliew contains some data bound elements called "entries". An entry has a property called "date".

I just want my listview to show entries whose date is in between my two datepickes dates.

My xaml code for binding the listview to the entries and dates:

<ListView.ItemsSource>
  <MultiBinding Converter="{StaticResource EntriesFilterConv}"
                UpdateSourceTrigger="PropertyChanged">
    <Binding Path="Entries" UpdateSourceTrigger="PropertyChanged"/>
    <Binding ElementName="EntryFromDate" Path="SelectedDate"
             UpdateSourceTrigger="PropertyChanged"/>
    <Binding ElementName="EntryToDate" Path="SelectedDate"
             UpdateSourceTrigger="PropertyChanged"/>
  </MultiBinding>
</ListView.ItemsSource>

However, this doesnt work. My converter is called when a SelectedDate changes but its never called when Entries changes.

With normal data binding like this:

<ListView ItemsSource="{Binding Entries}">
  ...
</ListView>

The listview updates normally. Any idea?

like image 293
Michael Hilus Avatar asked Apr 07 '11 15:04

Michael Hilus


2 Answers

I think the following might cause this: If you bind directly to the Entries the ListView will listen to CollectionChanged events, but if such a binding is inside a MultiBinding the only thing that would cause a reevaluation could be a PropertyChanged notification, which might not exist for the Entries property in your model.

Maybe you can subscribe to the CollectionChanged event of your collection and raise a PropertyChanged event or get the BindingExpression within your MultiBinding to call an update manually.

like image 131
H.B. Avatar answered Nov 14 '22 23:11

H.B.


After searching for hours, I find a simple and decent answer ! Since ObservableCollection doesn't raise PropertyChanged event but CollectionChanged, we just have to bind the collection's Count to fire the event when the list changes :

<MultiBinding Converter="{Resources:ListToStringConverter}">
    <Binding Path="List.Count" />
    <Binding Path="List" />
</MultiBinding>

Original infos about this perfectly working multibinding here : https://stackoverflow.com/a/10884002/817504

like image 20
Profet Avatar answered Nov 14 '22 21:11

Profet