导航服务导航枢轴错误

时间:2013-07-12 13:35:55

标签: c# windows-phone-7 navigation pivot

this.NavigationService.Navigate(new Uri("/MainPage.xaml?pivott.SelectedIndex = 0", UriKind.Relative));

我使用此代码导航我的pivot index = 0并且它可以工作一次。当我打电话给第二个,我的程序stops.not退出但停止。这可能是什么原因?我怎么解决?

1 个答案:

答案 0 :(得分:0)

我不知道你在努力做什么。但我知道情况是在导航时将枢轴索引更改为1。好的,我会动态选择枢轴索引。

在我将导航到Sample.xaml的主页中:

NavigationService.Navigate(new Uri("/Sample.xaml?id=1", UriKind.Relative));

在Sample.xaml中输入以下代码:

 protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        string index;
        int number=0;
        if (NavigationContext.QueryString.TryGetValue("id", out index))
        {
            if (Int32.TryParse(index, out number))
            {
                PivotItem.SelectedIndex = number;
            }
        }
    }

通过更改主页面上的id值来更改索引值。