Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to sort CollectionViewSource's groups

Tags:

c#

.net

wpf

xaml

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.

like image 996
Poma Avatar asked Dec 15 '10 20:12

Poma


1 Answers

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> 
like image 178
Szymon Rozga Avatar answered Sep 27 '22 20:09

Szymon Rozga