1

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.

4

2 に答える 2

1

IComparableオブジェクトをコレクションに追加するためのインターフェイスを使用できます。次に、並べ替えることができます

 IComparable getName()  // this should return company/employee name

比較メソッドでは、要件に従って並べ替えることができます

于 2010-02-01T13:06:47.903 に答える
0

「CompositeCollection」と呼ばれるものを活用しなければならないと誰が言いましたか?
CompositeCollection を使用しないことにしました。
2 つのタイプを混合した ObservableCollection(of Object) を作成し、CollectionViewSource をそれにバインドしています。

アップデート

CompositeCollection を継承して実装IBindingListすることで、ソートが可能になります。

于 2010-02-01T17:28:04.357 に答える