2014-09-05 68 views
1

我在XAML中Longliseselector Windows Phone的8
我正在填充它使用一個數據庫
它工作正常,不進行分組,但是當我組它只是顯示了幾個空列表Longlist選擇Windows Phone的

此代碼的工作

using (Database ctx = new Database(Database.ConnectionString)) 
     { 
      ctx.CreateIfNotExists(); 
      var tdr = from p in ctx.Transactions 
         join c in ctx.Type on p.Type equals c.Id 
         where p.Date > DateTime.Today.AddDays(-1 * ra) && c.Type1.Equals(ty) 
         select new { Id = p.Id, amont = p.Amont, type = c.Name, des = p.Des, dated = p.Date }; 
      list21.ItemsSource = tdr.ToList(); 
     } 

但是,當我組,所以我有跳轉列表它只是沒有沒有任何錯誤,工作

using (Database ctx = new Database(Database.ConnectionString)) 
     { 
      ctx.CreateIfNotExists(); 
      var tdr = from ii in 
          (
           from p in ctx.Transactions 
           join c in ctx.Type on p.Type equals c.Id 
           where p.Date > DateTime.Today.AddDays(-1 * ra) && c.Type1.Equals(ty) 
           select new { Id = p.Id, amont = p.Amont, type = c.Name, des = p.Des, dated = p.Date } 
          ) 
         group ii by ii.Id; 

      list32.ItemsSource = tdr.ToList(); 
     } 

我做錯了什麼?

+0

看來你是被錯誤的分組值爲 – sexta13 2014-09-05 16:22:56

+0

爲什麼?我想按這個分組。不同的類別名稱被選中並跳轉到。 – Raminhz 2014-09-05 16:47:43

回答

1

http://msdn.microsoft.com/en-us/library/windows/apps/jj244365(v=vs.105).aspx

你已經錯過了KeyedList ... 嘗試:

{ 
     ctx.CreateIfNotExists(); 
     var tdr = from ii in 
         (
          from p in ctx.Transactions 
          join c in ctx.Type on p.Type equals c.Id 
          where p.Date > DateTime.Today.AddDays(-1 * ra) && c.Type1.Equals(ty) 
          select new { Id = p.Id, amont = p.Amont, type = c.Name, des = p.Des, dated = p.Date } 
         ) 
        group ii by ii.Id into iii select new KeyedList<string, COLLECTIONITEM>(iii); 

     list32.ItemsSource = new List<KeyedList<string, COLLECTIONITEM>>(tdr); 
    } 



public class KeyedList<TKey, TItem> : List<TItem> 
    { 
     public TKey Key { protected set; get; } 

     public KeyedList(TKey key, IEnumerable<TItem> items) 
      : base(items) 
     { 
      Key = key; 
     } 

     public KeyedList(IGrouping<TKey, TItem> grouping) 
      : base(grouping) 
     { 
      Key = grouping.Key; 
     } 
    } 

不要在GroupHeaderTemplate忘記:

<TextBlock Text="{Binding Key}" /> 
相關問題