首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Windows Mobile >

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

2013-01-04 
Linq 联合查询 不能绑定到 ListBoxvar query from o in UserModel.GetInstance().DB.DBUsersjoin p in U

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">


                                <TextBlock Text="{Binding Path=Name}"/>
                                <TextBlock Text="{Binding Path=Age}" />
                                <TextBlock Text="{Binding Path=Desc}" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>



不解这是啥原因...
[解决办法]
绑定的时机是否正确?

[解决办法]
我不确定你是否需要实现INotifyPropertyChanged去更新你的数据显示
[解决办法]
数据绑定的思路是没有问题的,你可以调试一下,看一下查询出来的query有数据吗?

热点排行