<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; }
}
}
帮忙看下啊 就是数据显示不出来
调试一下from n in names
where (n.Sex == 1)
orderby n.Name
select new BabyName(n.Name, n.Sex);
有没有数据
用个foreach 打印一下