我有一个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