Marlon Grech

Hi there,

I have a composite collection and I am trying to implement sorting on this collection. When I call the CollectionViewSource.GetDefaultView I get a CompositeCollectionView.

I need to implement cutom sorting on this collection view just like you can do with the ListCollectionView yet this object does not have a customSort property...

how can I transform this view into a ListCollectionView or any other workarounds.... another thing I am trying to do a customsort since the SortDescription throws a NotSupportedException....

Thanks in advance for the help...

Re: Windows Presentation Foundation (WPF) Sorting on a Composite Collection throws a NotSupportedException

Marlon Grech

P.S the collection view that is returned from the CollectionViewSource.GetDefaultView is a CompsiteCollectionView. This is an internal class so I cannot see it nor subclass it or any thing...

I would really appreciate if someone from the WPF Data Team could help me ...


Re: Windows Presentation Foundation (WPF) Sorting on a Composite Collection throws a NotSupportedException

Marlon Grech

hi all

i created a simple test app to show you guys the exception that i get


so code behind page

Code Snippet

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace TestCompositeCollection
public class A
string test;
public string Test { get { return test; } set { test = value; } }

public A(string a)
test = a;

/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class Window1 : Window
ObservableCollection<A> list1;
public Window1()

list1 = new ObservableCollection<A>();
for (int i = 0; i < 9; i++)
list1.Add(new A(i.ToString()));

ObservableCollection<A> list2 = new ObservableCollection<A>();
for (int i = 10; i < 19; i++)
list2.Add(new A(i.ToString()));

CompositeCollection col = new CompositeCollection();
CollectionContainer c = new CollectionContainer();
c.Collection = list1;

c = new CollectionContainer();
c.Collection = list2;

CompositeCollection list = new CompositeCollection();
c = new CollectionContainer();
c.Collection = col;

testList.ItemsSource = list;

AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(test1));


public void test1(object sender, RoutedEventArgs e)
ICollectionView view = CollectionViewSource.GetDefaultView(testList.ItemsSource);
view.SortDescriptions.Add(new SortDescription("Test", ListSortDirection.Ascending));

public void test(object sender, RoutedEventArgs e)
list1.Add(new A("s"));

The exception is raised when i add a sort description...

Code Snippet

<Window x:Class="TestCompositeCollection.Window1"
Title="Window1" Height="300" Width="300"
<RowDefinition Height="0.9*"/>
<RowDefinition Height="0.1*"/>

<ListView Name="testList" Grid.Row="0">
<GridViewColumn DisplayMemberBinding="{Binding Test}" Header="test" />

<Button Content="hhhhh" Click="test" Grid.Row="1"/>


Re: Windows Presentation Foundation (WPF) Sorting on a Composite Collection throws a NotSupportedException

Sam Bent - MSFT

WPF does not support sorting a CompositeCollection. You'll have a difficult time converting it to ListCollectionView, especially if you add/remove items from the individual collections.

I'm afraid you're in a tight spot.