当前位置: 代码迷 >> Windows Mobile >> Linq 联合查询 不能绑定到 ListBox解决办法
  详细解决方案

Linq 联合查询 不能绑定到 ListBox解决办法

热度:4078   发布时间:2013-02-26 00:00:00.0
Linq 联合查询 不能绑定到 ListBox

            var query = from o in UserModel.GetInstance().DB.DBUsers
                        join p in UGroupModel.GetInstance().DB.DBUGroups
                        on o.ID equals p.ID
                        select new
                        {
                            o.ID,
                            o.Name,
                            o.Age,
                            p.Desc
                        };

            //var query = from UGroupTable user in UGroupModel.GetInstance().DB.DBUGroups
            //            select user; //使用这句话可以成功绑定到ListBox

            int RecCount = query.Count(); //这里的RecCount是大于0的,证明读到值了            
            foreach (var t in query)
            { //这里也能看到t里是有值的
            }
            listBox3.ItemsSource = query.ToList();


xaml代码:

            <ListBox  Height="Auto" HorizontalAlignment="Left" Margin="0,300,0,0" Name="listBox3" VerticalAlignment="Top" Width="Auto">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <TextBlock Text="{Binding Path=ID}"/>
                            <StackPanel Orientation="Horizontal">
  相关解决方案