我正在尝试对包含以下类
的ObservabkeCollection对象进行排序 public Favourites(string title=null, string uri=null, string folder=null, bool delete=false)
{
this.pageTitle = title;
this.pageURI = uri;
this.folder = folder;
this.deleteEnabled = delete;
}
我正在尝试按文件夹排序,然后按uri排序。虽然uri和title可以为null,但在我的情况下,我总是给它们分配一些非空的东西。但是,folder属性可以为null。
我要排序的代码
private void sortCollectionFolderFirst()
{
IEnumerable<Favourites> sort;
ObservableCollection<Favourites> tempSortedFavourites = new ObservableCollection<Favourites>();
tempFavs.Clear();
tempFavs = settings.FavouritesSetting;
sort = tempFavs.OrderByDescending(item => item.Folder).ThenBy(item => item.PageURI);
foreach (var item in sort)
{
tempSortedFavourites.Add(item);
}
settings.FavouritesSetting = tempSortedFavourites;
}
当课程项目
时,排序很好this.pageTitle = sometitle;
this.pageURI = someuri;
this.folder = null;
this.deleteEnabled = false or true;
但sort
在遇到具有以下内容的项目
this.pageTitle = sometitle;
this.pageURI = someuri;
this.folder = somefoldername;
this.deleteEnabled = false or true;
为什么?