首页 新闻 搜索 专区 学院

wp7 ListBox绑定之后不显示数据

0
悬赏园豆:20 [已关闭问题] 关闭于 2012-03-14 21:06
<phone:PhoneApplicationPage 
x:Class="PivotApp.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">

<!--LayoutRoot 是包含所有页面内容的根网格-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<controls:Pivot Title="BABY NAMES">
<controls:PivotItem Header="boys">
<ListBox x:Name="boyList" Margin="0,0,-12,0" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" DataContext="{Binding}">
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

</controls:PivotItem>

<controls:PivotItem Header="girls" >
<ListBox x:Name="girlList" Margin="0,0,-12,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" >
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

</controls:PivotItem>

<controls:PivotItem Header="either">
<ListBox x:Name="allList" Margin="0,0,-12,0">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" >
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>

</controls:PivotItem>
</controls:Pivot>
</Grid>

</phone:PhoneApplicationPage>




using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;

namespace PivotApp
{
public partial class MainPage : PhoneApplicationPage
{
BabyName[] names = new BabyName[10] {new BabyName("Steve", 1),
new BabyName("Jennifer", 2),
new BabyName("Alex", 1),
new BabyName("Casey", 1),
new BabyName("Quinn", 1),
new BabyName("Anthony", 1),
new BabyName("Sarah", 2),
new BabyName("Parker", 2),
new BabyName("Jessica", 2),
new BabyName("Jeff", 1)};

// 构造函数
public MainPage()
{
InitializeComponent();
boyList.ItemsSource = from n in names
where (n.Sex == 1)
orderby n.Name
select new BabyName(n.Name, n.Sex);

girlList.ItemsSource = from n in names
where (n.Sex == 2)
orderby n.Name
select new BabyName(n.Name, n.Sex);

allList.ItemsSource = from n in names
orderby n.Name
select new BabyName(n.Name, n.Sex);


}
}

class BabyName
{
public BabyName(string name, int sex)
{
Name = name;
Sex = sex;
}
public string Name { get; set; }
public int Sex { get; set; }
}
}


帮忙看下啊   就是数据显示不出来   

HoYO的主页 HoYO | 初学一级 | 园豆:80
提问于:2012-03-14 20:30
< >
分享
所有回答(1)
0

调试一下from n in names
                                  where (n.Sex == 1)
                                  orderby n.Name
                                  select new BabyName(n.Name, n.Sex);
有没有数据

用个foreach 打印一下

walleyekneel | 园豆:304 (菜鸟二级) | 2012-04-19 10:53
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册