开发者

How to force ListView manually recreate view using its .Items.Filter?

开发者 https://www.devze.com 2023-04-11 16:35 出处:网络
I got a ListView with an ItemsSource collection, where ObservableCollection<string> is set. And, the ListView contains a filter in its ListView.Items.Filter property (as a Predicate<bool,obje

I got a ListView with an ItemsSource collection, where ObservableCollection<string> is set. And, the ListView contains a filter in its ListView.Items.Filter property (as a Predicate<bool,object>.

So let's say there are conditions when the filter can change its behavior without changing its own reference.

And when those conditions change i need to let the ListView know that it has to reconstruct its view according to the new filter.

The only solution i've figured is

ListView.Items.Filter =开发者_运维技巧 ListView.Items.Filter;

which is wrong but it still works. Updates each item again with the filter.

So is there right solution for that?


You need to get a hold of the collection view (ICollectionView) that the ListView is bound to and Refresh() it. It's not clear to me how you've bound to your data, but you can either:

  • Bind to a collection view explicitly
  • Bind to a collection and have the control automatically bind to the default collection view

It sounds like you've done the latter, in which case you can use:

CollectionViewSource.GetDefaultView(theCollection).Refresh();
0

精彩评论

暂无评论...
验证码 换一张
取 消