我有这段代码:
var selected = from c in myList group c by c.MainTitle into n select new GroupingLayer<string, MyObject>(n);
longListSelector.ItemsSource = selected; //Error here
public class GroupingLayer<TKey, TElement> : IGrouping<TKey, TElement>
{
private readonly IGrouping<TKey, TElement> grouping;
public GroupingLayer(IGrouping<TKey, TElement> unit)
{
grouping = unit;
}
public TKey Key
{
get { return grouping.Key; }
}
public IEnumerator<TElement> GetEnumerator()
{
return grouping.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return grouping.GetEnumerator();
}
}
它试图告诉我什么?,如何解决这个问题?
我正在使用Windows Phone 8应用程序。
答案 0 :(得分:1)
它告诉您longListSelector.ItemsSource
的类型为IList
,但selected
中存储的值为IEnumerable
,您无法将其分配给另一个。
尝试拨打ToList()
:
var selected = (from c in myList
group c by c.MainTitle into n
select new GroupingLayer<string, MyObject>(n)).ToList();
longListSelector.ItemsSource = selected;