Poma
Poma

Reputation: 8474

How to sort CollectionViewSource's groups

I have following collection view

<CollectionViewSource x:Key="messages" Source="{Binding src}">
    <CollectionViewSource.GroupDescriptions>
        <PropertyGroupDescription PropertyName="Group"/>
    </CollectionViewSource.GroupDescriptions>
</CollectionViewSource>

Then I assign it to TreeView's ItemsSource. Now, how to sort Groups by their name? They appear to have random order.

Upvotes: 5

Views: 3954

Answers (1)

Szymon Rozga
Szymon Rozga

Reputation: 18168

Just sort by the group. This should work:

<CollectionViewSource x:Key="messages" Source="{Binding src}"> 
    <CollectionViewSource.GroupDescriptions> 
        <PropertyGroupDescription PropertyName="Group"/> 
    </CollectionViewSource.GroupDescriptions> 
    <CollectionViewSource.SortDescriptions>
        <SortDescription PropertyName="Group" />
    </CollectionViewSource.SortDescriptions>
</CollectionViewSource> 

Upvotes: 7

Related Questions