Is there a list that is sorted automatically in .NET?

前端 未结 8 1181
轻奢々
轻奢々 2021-02-05 04:00

I have a collection of Layers where they have names and colors. What I want to do is to sort these first based on colors, then based on their names:



        
8条回答
  •  既然无缘
    2021-02-05 04:25

    If the sort is only for display purposes, let WPF handle it:

    ICollectionView view = CollectionViewSource.GetDefaultView(Layers);
    view.SortDescriptions.Add(new SortDescription("Color", ListSortDirection.Ascending);
    view.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending);
    

    then just bind Layers to your UI ItemsControl.

提交回复
热议问题