长列表选择器窗口电话

时间:2014-09-05 13:42:50

标签: c# windows-phone-8 linq-to-sql group-by

我在Xaml中有一个用于Windows Phone 8的Longliseselector 我使用数据库填充它 它没有分组工作正常,但当我分组它只显示一些空列表

此代码有效

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();
        }  

我做错了什么?

1 个答案:

答案 0 :(得分: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}" />