如何强制 ListView 使用其 .Items.Filter 手动重新创建视图?
我得到了一个带有 ItemsSource
集合的 ListView
,其中设置了 ObservableCollection
。 并且,ListView
在其 ListView.Items.Filter
属性中包含一个过滤器(作为 Predicate
)。
所以我们可以说 过滤器可以在不更改其自身引用的情况下更改其行为的条件,
并且当这些条件发生变化时,我需要让 ListView 知道它必须根据新过滤器重建其视图。
是 我发现
ListView.Items.Filter = ListView.Items.Filter;
哪个是错误的但它仍然可以使用过滤器再次更新每个项目,
那么有正确的解决方案吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要获取
ListView
绑定到的集合视图 (ICollectionView
) 并对其进行Refresh()
。我不清楚您如何绑定到数据,但您可以:听起来您已经完成了后者,在这种情况下你可以使用:
You need to get a hold of the collection view (
ICollectionView
) that theListView
is bound to andRefresh()
it. It's not clear to me how you've bound to your data, but you can either:It sounds like you've done the latter, in which case you can use: