如何在C#中对Observablecollection进行排序 [英] How Do I Sort An Observablecollection In C#
本文介绍了如何在C#中对Observablecollection进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个
ObservableCollection<T>
,它有两个属性String Item和String Priority。
i希望我的LongListSelector显示优先级为高的项目先分别为低。
i尝试了这个但看起来像是一个愚蠢的想法,但我不是一个好的程序员,但我是中间的。
, it has two properties String Item and String Priority.
i want my LongListSelector to display the items with Priority "High" first then "Low" respectively.
i have tried this but it seem like a stupid idea but i am not that good a programmer yet i am intermediate.
this.List.ItemsSource = this.Items.OrderBy(c => c.Priority == "High");
感谢您的贡献。
thank you for your contribution.
推荐答案
如果您想对数据进行排序按升序排列,使用:
If you want to sort data in ascending order, use:
this.List.ItemsSource = this.Items.OrderBy(c => c.Priority);
下降orde r,使用:
For descending order, use:
this.List.ItemsSource = this.Items.OrderByDescending(c => c.Priority);
这就是全部;)
注意:列表中项目的顺序不会改变。你需要实现它。
请阅读:
如何对ObservableCollection的降序进行排序? [ ^ ]
如何对ObservableCollection进行排序 [ ^ ]
这篇关于如何在C#中对Observablecollection进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文