WP7 ObservableCollection sorting

本文关键字:sorting ObservableCollection WP7 | 更新日期: 2023-09-27 18:28:56

我有一个集合:

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

然后在我把4个元素放进去(它显示正确)后,我试着对它们进行排序

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

ShopList现在有4个空元素。为什么会这样,以及如何更正代码?感谢

WP7 ObservableCollection sorting

这是正确的顺序:

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