7,657
社区成员
发帖
与我相关
我的任务
分享
public class ViewModel
{
private ObservableCollection<TestPivot> _bindData;
public ObservableCollection<TestPivot> BindData
{
get
{
return _bindData;
}
set
{
if (value != _bindData)
{
_bindData = value;
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifiPropertyChanged(string bindData)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this,new PropertyChangedEventArgs(bindData));
}
}
public void AddData(int size)
{
BindData=new ObservableCollection<TestPivot>();
for (int i = 0; i < size; i++)
{
TestPivot t = new TestPivot();
t.Name = "piovt item" + i;
t.ListData = new List<string>();
for (int j = 0; j < 10; j++)
{
t.ListData.Add("List item" + j);
}
BindData.Add(t);
}
}
}
public class TestPivot
{
public string Name { get; set; }
public List<string> ListData { get; set; }
}
<phone:PhoneApplicationPage
x:Class="Demo.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:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DataContext="{d:DesignData SampleData/MainViewModelSampleData.xaml}"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True">
<phone:PhoneApplicationPage.Resources>
<DataTemplate x:Key="DT_pivot">
<ListBox ItemsSource="{Binding ListData}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
<DataTemplate x:Key="DT_Header">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot 是包含所有页面内容的根网格-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<phone:Pivot Title="我的应用程序"
ItemsSource="{Binding BindData}"
ItemTemplate="{StaticResource DT_pivot}"
HeaderTemplate="{StaticResource DT_Header}">
</phone:Pivot>
</Grid>
</phone:PhoneApplicationPage>