无法将类型'System.Collections.Generic.IEnumerable GroupingLayer隐式转换为'System.Collections.IList'

时间:2014-02-24 12:49:08

标签: c# wpf windows-phone-8 windows-phone longlistselector

我有这段代码:

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应用程序。

1 个答案:

答案 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;
相关问题