MultiBinding with MultiValueConverter does not update

It looks like I have a problem with my multiply-connected interface.

Scenario:
I have a window with two datepickers and a listview. Listliew contains some data-related items called "records." A record has a property called "date."

I just want my list to display entries whose date is between two date dates.

My xaml code to bind a list to records 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 does not work. My converter is called when SelectedDate changes, but it is never called when a record changes.

With normal data binding, for example:

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

The list is usually updated. Any idea?

+6
source share
2 answers

I think the following can lead to the following: if you bind directly to Entries , the ListView will listen for CollectionChanged events, but if such a binding is inside a MultiBinding , the only thing that can lead to a reevaluation is a PropertyChanged notification, which may not exist for the property " Records "in your model.

Perhaps you can subscribe to the CollectionChanged event of your collection and raise the PropertyChanged event or get a BindingExpression in your MultiBinding to trigger the update manually.

+4
source

After searching the watch, I find a simple and decent answer! Since the ObservableCollection does not raise the PropertyChanged event, but the CollectionChanged event, we just need to bind the Count collection to fire the event when the list changes:

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

Original information about this great multiplexing here: fooobar.com/questions/885430 / ...

+8
source

Source: https://habr.com/ru/post/885428/


All Articles