How do you force a WPF ListView to Requery its ItemSource?

非 Y 不嫁゛ 提交于 2019-12-10 06:41:11

问题


I'm rewriting its XML itemSource on the fly and want it to use the new data right away...


回答1:


You should use an ObervableCollection. When this collection is updated, the ListView is updated.

But if for any reason you don´t want to use one, use:

listView.InvalidateProperty(ListView.ItemsSourceProperty);

or

listView.ItemsSource = listView.ItemsSource;

Check A more elegant ListView requery for more info.




回答2:


hmm...

listView.ItemsSource = listView.ItemsSource?

or you could trigger the PropertyChanged event on the property of your viewmodel in case you are using MVVM.




回答3:


ListView.DataBind(); MSDN



来源:https://stackoverflow.com/questions/1111338/how-do-you-force-a-wpf-listview-to-requery-its-itemsource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!