如何使用 CollectionView 功能处理 CompositeCollection?
有没有办法在 CompositeCollection 的当前位置发生变化时收到通知?
我需要通过 CollectionView 监视 CompositeCollection,欢迎任何想法。
Is there a way to get notified when CompositeCollection's current location changes?
I need to have the CompositeCollection monitored by a CollectionView, any ideas are welcommed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过监视 CollectionView 的
ICollectionView.CurrentChanged
事件来检测当前项目何时发生更改。以下代码适用于我:当我更改列表框中的选择时,将显示消息框。
关于过滤、排序和分组,根据 Aron 的回答,这些在 CompositeCollection 的视图上不可用。但为了记录,这里是您可以检测确实支持这些功能的视图更改的方法:
You can detect when the current item has changed by monitoring the
ICollectionView.CurrentChanged
event of your CollectionView. The following code works for me:When I change the selection in the ListBox, the message box displays.
Regarding filtering, sorting and grouping, as per Aron's answer these are not available on a view over a CompositeCollection. But for the record here are the ways you can detect changes for views that do support these features:
ObservableCollection<GroupDescription>
, so hook up a CollectionChanged event handler on the GroupDescriptions property.您无法在复合集合上运行 CollectionView,请参阅此处
You cant run a CollectionView on a copmposite collection, see here
我遇到了同样的问题:我需要对 CompositeCollection 进行排序。我编写了以下类来解决这个问题,至少对于相同类型的 ObservableCollections 来说是这样。
这个想法是将复合集合作为普通的可观察集合来维护,并随着底层集合的变化而更新它。然后生成的集合(AllNodes)可以在用户界面中使用,并且它支持 CollectionView 就好了。
I ran into the same problem: I needed sorting of a CompositeCollection. I wrote the following class that solves the problem, at least for ObservableCollections of the same type.
The idea is to maintain the composite collection as an ordinary observable collection, and update it as the underlying collections change. Then the resulting collection (AllNodes) can be used in the user interface, and it supports CollectionView just fine.