我有一個Observable Collection其中包含我的數據值。我想在該收藏中使用Orderby,但我收到一些例外,如 "Cannot convert IEnumurable to ObservableCollection"
。有沒有可能使用OrderBy或給我一些選擇排序收藏?將IEnumurable轉換爲Observable Collection而不創建Observable collection的新實例
任何人都請告訴我這個的解決方案。 在此先感謝。
我的代碼是:
get {
return _availableStocks == null ? null : _availableStocks .OrderBy(z => z.Casepack.CasePackContents);
// Here _availableStocks is my collection
//Here i am not able to use orderby in this collection Its showing error line
// Here i need to sort the _availableStocks
}
我實際的代碼是:
foreach (var cachedStock in AvailableSelectedStocks)
{
if (SelectedStock != null)
{
AvailableStocks= CollectionViewSource.GetDefaultView(_availableStocks);
AvailableStocks.SortDescriptions.Add(new SortDescription(SelectedStock.Casepack.CasePackContents.Count.ToString(), ListSortDirection.Ascending));
//In this above line i am getting the Sort descriptions only i am not getting the datas in the SourceCollection . how can i get values in this Collection
this.SelectedStocks.Remove(SelectedStock);
this.RaisePropertyChanged(Member.Of(() => AvailableStocks));
}
}
異常或編譯器錯誤?你能說明這個財產是如何被使用的嗎? – 2012-02-14 05:40:28
其編譯錯誤 – SuryaKavitha 2012-02-14 05:47:49