简体   繁体   English

如何对CollectionViewSource的组进行排序

[英]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. 然后,将其分配给TreeView的ItemsSource。 Now, how to sort Groups by their name? 现在,如何按名称对进行排序? They appear to have random order. 它们似乎具有随机顺序。

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> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM