【发布时间】:2015-12-31 03:16:38
【问题描述】:
我使用this 作为模板,但在 Windows Phone 模拟器中没有显示任何内容。我正在尝试将字符串列表绑定到ItemsControl。当我这样做时不会工作。我也在尝试使用StackPanel,但我删除了以尝试使其正常工作。
PivotPage.xaml:
<Page
x:Class="WinPhone8__Practice.PivotPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:WinPhone8__Practice"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:data="using:WinPhone8__Practice.Data"
mc:Ignorable="d"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page.Transitions>
<TransitionCollection>
<NavigationThemeTransition>
<NavigationThemeTransition.DefaultNavigationTransitionInfo>
<CommonNavigationTransitionInfo IsStaggeringEnabled="True"/>
</NavigationThemeTransition.DefaultNavigationTransitionInfo>
</NavigationThemeTransition>
</TransitionCollection>
</Page.Transitions>
<Grid>
<Pivot x:Uid="Pivot" Title="MY APPLICATION" x:Name="pivot" CommonNavigationTransitionInfo.IsStaggerElement="True">
<!--Pivot item one-->
<PivotItem
x:Uid="PivotItem1"
Margin="19,14.5,0,0"
CommonNavigationTransitionInfo.IsStaggerElement="True">
<!--Double line list with text wrapping-->
<ItemsControl ItemsSource="{Binding strings}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</PivotItem>
</Pivot>
</Grid>
</Page>
PivotPage.xaml.cs:
public sealed partial class PivotPage : Page
{
private readonly NavigationHelper navigationHelper;
public List<string> strings { get; private set; }
public PivotPage()
{
this.InitializeComponent();
strings = new List<string>() { "Yes", "No", "Maybe", "I don't know", "Can you repeat the question?" };
this.NavigationCacheMode = NavigationCacheMode.Required;
this.navigationHelper = new NavigationHelper(this);
this.navigationHelper.LoadState += this.NavigationHelper_LoadState;
this.navigationHelper.SaveState += this.NavigationHelper_SaveState;
}
/// <summary>
/// Gets the <see cref="NavigationHelper"/> associated with this <see cref="Page"/>.
/// </summary>
public NavigationHelper NavigationHelper
{
get { return this.navigationHelper; }
}
private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
await DoNothing();
}
private void NavigationHelper_SaveState(object sender, SaveStateEventArgs e)
{
// TODO: Save the unique state of the page here.
}
private Task DoNothing() { return new Task(new Action(() => { })); }
}
【问题讨论】:
标签: c# xaml binding windows-phone-8.1 itemscontrol