简体   繁体   中英

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

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

ShopList now has 4 null elements. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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