我正在尝试对包含以下类的 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 可以为空,但在我的情况下,我总是为它们分配不为空的东西。但是,文件夹属性可以为空。
我要排序的代码
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;
这是为什么?