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(); //[color=#FF0000]这里的RecCount是大于0的,证明读到值了[/color] foreach (var t in query) { //[color=#FF0000]这里也能看到t里是有值的[/color] } listBox3.ItemsSource = query.ToList();
<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>