将结果分组绑定到wp7中的列表框 [英] bind group by result to listbox in wp7

查看:65
本文介绍了将结果分组绑定到wp7中的列表框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的桌子是这样的
1)Item_table:

 id
列表名称
分类名称
项目名称
价格
数量
数量


我想这样显示

类别名称(计数)

item1数量价格
item2数量价格

category_name(计数)

item1数量价格
item2数量价格


到目前为止,我已经尝试过列表框设计:

 <   ListBox     x:Name   ="    宽度  ="  440" <   ListBox.ItemTemplate  > 
                            <   DataTemplate  > 
                        <   TextBlock     ="   {Binding category_name}" <  > 
                        <   TextBlock     ="   {Binding item_name}"  FontSize    28" <  > 
                        <   TextBlock     ="   {Binding qty}"  FontSize    24" <  > 

                                <  /Grid  > 
                            <  /DataTemplate  > 
                        <  /ListBox.ItemTemplate  > 
                    <  /ListBox  >  


 公共  void  itemlist()
    {

     var 查询= 来自 shoppingItem w 数据库中.Item1
                    通过 {w.category_name} 分组 w进入跨度> g
                    选择  {category = g.Key.category_name,g};
    } 


但是我应该如何将查询变量转换为列表,以便可以将其绑定到列表框.将LINQ查询结果转换为列表的方法,即使用ToList() 方法.

该技术看起来很像WPF或Silverlight.这意味着您必须将ListBox的ItemsSource设置为该类的IEnumerable,该类包含具有属性category_name,item_name和qty的对象的集合.这意味着我对按查询分组感到有些困惑.您不需要,因为您需要类别名称.我认为您需要的是:

  var 查询= 来自 shoppingItem  db.Items
                    选择  {shoppingItem.category_name,
                                 shoppingItem.item_name,
                                 shoppingItem.qty}; 



由于我对您的问题一无所知,请原谅我的错误.


您可以通过查询表达式获得IEnumerable.

您可以直接将其分配给列表框的itemsource.

根据您的要求LongListSelector适合.尝试使用工具包Longlistselector.


my table is look like this
1)Item_table:

id
list_name
category_name
item_name
price
qty
amount


i want to display it like this

category_name (count)

item1 qty price
item2 qty price

category_name (count)

item1 qty price
item2 qty price


till now i had tried listbox design:

<ListBox x:Name="listbox_all_items" Width="440">
                        <ListBox.ItemTemplate>
                            <DataTemplate>
                        <TextBlock Text="{Binding category_name}"></TextBlock>
                        <TextBlock Text="{Binding item_name}" FontSize="28"></TextBlock>
                        <TextBlock Text="{Binding qty}" FontSize="24"></TextBlock>

                                </Grid>
                            </DataTemplate>
                        </ListBox.ItemTemplate>
                    </ListBox>


public void itemlist()
    {

    var query = from shoppingItem w in db.Item1
                    group w by new { w.category_name } into g
                    select new { category = g.Key.category_name, g };
    }


but how should I convert query variable to list so that i can bind it listbox.

解决方案

I am a little confused by the quesiton, but I there is a very easy way to convert a LINQ query result to a list and that is to use the ToList() method.

The technolgy looks a lot like WPF or Silverlight. That means that you will have to set the ItemsSource for the ListBox to an IEnumerable of the class that contains the collection of objects with the properties category_name, item_name, and qty. This means that I am a little confused about the group by query. You don''t need because you need tha category name. What I think you need is:

var query = from shoppingItem in db.Items
                    select new { shoppingItem.category_name, 
                                 shoppingItem.item_name,
                                 shoppingItem.qty};



Pardon errors due to me not knowing everything about your problem.


You can get IEnumerable as a result of query expression.

You can directly assign this to itemsource of listbox.

For your requirement LongListSelector suits. Try Toolkit Longlistselector.


这篇关于将结果分组绑定到wp7中的列表框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆