一个更优雅的ListView重新查询 [英] A more elegant ListView requery
本文介绍了一个更优雅的ListView重新查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要我的的ListView
其他控制的 IsChanged
事件被触发,每次刷新。我GOOGLE了关于如何做到这一点,我就看见一个计算器的链接,导致我的here
I need to refresh my ListView
every time the another control's IsChanged
event is fired. I googled on how to do that, and I saw a stackoverflow link that led me here
答案之一工作:
listView.ItemsSource = listView.ItemsSource
这真的只有这样,才能刷新我的的ListView
?它有点感觉了。
推荐答案
只是使它无效。
listView.InvalidateProperty(ListView.ItemsSourceProperty)
这应该做到这一点。
顺便说一句,我真的会建议看MVVM。它往往是更强大。在这种情况下,对于一个MVVM应用程序,我只想做到这一点:
As an aside, I would really suggest looking at MVVM. It tends to be much more powerful. In this case, for an MVVM application, I would just do this:
XAML中:
<ListView ItemsSource="{Binding MyItems}" />
这将是我的ViewModel我绑定到:
And here would be my ViewModel I'm binding to:
public ObservableCollection<MyItem> MyItems
{
get; set;
}
public void IsChangedHandler(...)
{
...
this.OnPropertyChanged("MyItems");
}
这篇关于一个更优雅的ListView重新查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文