列表框选择事件页面导航Windows Phone 8

时间:2014-08-19 15:07:20

标签: c# windows-phone-8 listbox

我正在创建一个包含ListBox控件的简单应用程序。我想在用户点击任何列表项时导航到另一个页面。我的ListBox包含17个列表项。我使用了一个解决方案,但它只导航到page_1,我无法导航到其他页面。我做错了什么?

MainPage.xaml中

<phone:PivotItem Header="hello" FontSize="20">
    <!--Double line list no text wrapping-->
    <ListBox x:Name="list1" SelectionChanged="lis1cng" Margin="0,0,-12,0" ItemsSource="{Binding Items}">
        <ListBox.ItemTemplate >
            <DataTemplate>
                <StackPanel Margin="0,0,0,17">
                    <TextBlock Text="{Binding LineOne}" TextWrapping="Wrap" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="30"/>
                </StackPanel>
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
<phone:PivotItem>

MainPage.cs

private void lis1cng(object sender, SelectionChangedEventArgs e)
{
    // If selected index is -1 (no selection) do nothing
    if (list1.SelectedIndex == -1)
        return;
    else if (list1.SelectedIndex == 0)
    {
        NavigationService.Navigate(new Uri("/page_1.xaml", UriKind.Relative));
    }
    else if (list1.SelectedIndex == 1)
    {
        NavigationService.Navigate(new Uri("/page_2.xaml", UriKind.Relative)); 
    }
    // Reset selected index to -1 (no selection)
    list1.SelectedIndex = -1;
}

Page_1.xaml

 <phone:PhoneApplicationPage
        x:Class="PivotApp1.new"

Page_2.xaml

<phone:PhoneApplicationPage
    x:Class="PivotApp1.Page_2"

page_1.xaml&#39; x:class is pivotApp1.new 和 Page_2.xaml的x:class是pivotApp1.Page_2

这会造成问题吗?我该如何解决?

0 个答案:

没有答案