MultiBinding与MultiValueConverter不更新 [英] MultiBinding with MultiValueConverter does not update
问题描述
场景:
我有一个带有两个日期检视器和一个列表视图的窗口。
listliew包含一些称为条目的数据绑定元素。一个条目有一个名为date的属性。
我只想让我的列表显示日期在我的两个datepickes日期之间的条目。
我将用于将列表视图绑定到条目和日期的xaml代码:
< ListView.ItemsSource> ;
< MultiBinding Converter ={StaticResource EntriesFilterConv}
UpdateSourceTrigger =PropertyChanged>
< Binding Path =EntriesUpdateSourceTrigger =PropertyChanged/>
< Binding ElementName =EntryFromDatePath =SelectedDate
UpdateSourceTrigger =PropertyChanged/>
< Binding ElementName =EntryToDatePath =SelectedDate
UpdateSourceTrigger =PropertyChanged/>
< / MultiBinding>
< /ListView.ItemsSource>
但是,这不工作。当一个SelectedDate更改时,我的转换器被调用,但是当Entries发生变化时,它不会被调用。
正常的数据绑定如下:
< ListView ItemsSource ={Binding Entries}>
...
< / ListView>
列表视图正常更新。
任何想法?
我认为以下可能是这样的:如果你直接绑定到 Entries
ListView将收听 CollectionChanged
事件,但如果这样的绑定在 MultiBinding
唯一可能导致重新评估的事情可能是一个 PropertyChanged
通知,这可能不适用于模型中的Entries属性。
也许您可以订阅收藏的 CollectionChanged
事件,并提出一个 PropertyChanged
事件或在 MultiBinding
中获取 BindingExpression
以手动调用更新。
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?
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.
这篇关于MultiBinding与MultiValueConverter不更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!