关于如何对CompositeCollection进行排序的任何想法? [英] Any idea on how to sort a CompositeCollection?

查看:115
本文介绍了关于如何对CompositeCollection进行排序的任何想法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个CompositeCollection,它由两种类型的ObservableCollections组成:Company和Contacts. 联系人的属性为FullName,而公司的属性为Name.

我想应用排序,以便集合按其类型混合,但按其名称排序,例如:

Itzhak Perlman
约翰·杜(John Doe)
微软
莎拉·摩尔
StackOverflow
沃尔特·理查森

请注意,我将ItemsControl绑定到CollectionViewSource,其Source设置为CompositeCollection,它的视图变为CompositeCollectionView,它是内部类型,如果我将其类型显式设置为ListCollectionView,则仅包含CollectionContainers作为其项./p>

所需的解决方案是一种解决方法,可以对CompositeCollections进行排序,过滤和分组,我不在乎覆盖并创建自己的CompositeCollection,我只是不知道如何覆盖它并在xaml中启用其功能.

解决方案

谁说我必须利用称为"CompositeCollection"的东西?
我决定不使用CompositeCollection.
我只是创建两种类型混合的ObservableCollection(of Object),然后将CollectionViewSource绑定到它.

更新

通过继承CompositeCollection并实现 IBindingList ,可以启用排序.

I have a CompositeCollection that consists of ObservableCollections of two types: Companies and Contacts. Contact has a property FullName while Company has a property Name.

I want to apply sorting so the collections are mixed by their types but sorted by their name, example:

Itzhak Perlman
John Doe
Microsoft
Sarah Moore
StackOverflow
Walter Richardson

Note that I bound the ItemsControl to a CollectionViewSource that its Source is set the CompositeCollection, it's view becomes a CompositeCollectionView, it's an internal type, if I explicitly set its type to ListCollectionView, it only contains the CollectionContainers as its items.

Desired solution is a workaround to enable sorting, filtering and grouping on a CompositeCollections, I don't care to override and create my own CompositeCollection, I just don't know how I can override this and enable its functionality in xaml.

解决方案

Who said I must get advantage of the thingy called 'CompositeCollection'?
I decided not to use a CompositeCollection.
I am just creating an ObservableCollection(of Object) mixed of the two types, and binding the CollectionViewSource to it.

Update

By inheriting CompositeCollection and implenting IBindingList, sorting can be enabled.

这篇关于关于如何对CompositeCollection进行排序的任何想法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆