简体   繁体   English

WP7 ObservableCollection排序

[英]WP7 ObservableCollection sorting

I have a collection: 我有一个集合:

public ObservableCollection<Shops> ShopList { get; set; }

then after i put 4 elements in it(it is displayed correctly), i try to sort them 然后我把4个元素放入其中(它显示正确),我尝试对它们进行排序

ShopList.Clear();
var orderedlist = ShopList.OrderBy(k => k.Name);
foreach (Shops s in orderedlist)
    ShopList.Add((Shops)s);

ShopList now has 4 null elements. ShopList现在有4个null元素。 Why is that, and how to correct the code? 为什么这样,以及如何纠正代码? Thanks 谢谢

This is the correct order: 这是正确的顺序:

var orderedlist = ShopList.OrderBy(k => k.Name);
ShopList.Clear();
foreach (Shops s in orderedlist)
    ShopList.Add((Shops)s);

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

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