2014-02-24 37 views
0

我有這樣的代碼:無法隱式轉換類型「System.Collections.Generic.IEnumerable GroupingLayer爲‘System.Collections.IList’

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

它告訴你,longListSelector.ItemsSourceIList類型,但存儲在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; 
+0

你在嗎? – user2056563

+0

請看看這裏http://stackoverflow.com/questions/21986760/binding-data-in-longlistselector – user2056563

+0

你有看過嗎? – user2056563

相關問題