2014-09-05 37 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}" /> 
相关问题