问题描述
我创建了一个带有两个链接的 MainPage.两者都会将用户带到一个新的 Pivot 页面.但是,第一个链接将打开 Pivot 的第一页,而第二个链接将打开 Pivot 的第二页.
I have created a MainPage with two links. Both will take the user to a new Pivot page.However, the first link will open the first page of the Pivot, while the second will open the second page of the Pivot.
到目前为止我有以下代码:
I have the following code so far:
主页:
NavigationService.Navigate(new Uri("/PivotTester.xaml?goto=" + i, UriKind.Relative));
然后在 PivotTester 页面上:
and then on PivotTester page:
namespace CelticNow
{
public partial class PivotTester : PhoneApplicationPage
{
PivotTester pivot = new PivotTester();
public PivotTester()
{
InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string strItemIndex;
if (NavigationContext.QueryString.TryGetValue("goto", out strItemIndex))
pivot.SelectedIndex = Convert.ToInt32(strItemIndex);
base.OnNavigatedTo(e);
}
}
}
我添加了Pivot pivot = new...",因为使用 PivotTester.SelectedIndex 不起作用.
I added in the "Pivot pivot = new..." as using PivotTester.SelectedIndex wouldn't work.
任何人都可以提供有关我如何进行这项工作的解决方案吗?谢谢.
Can anyone provide a solution as to how I would make this work? Thanks.
推荐答案
This will help you, Remove the following line of code from your code
This will help you, Remove below line of code from your code
//Remove if not necessary
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string strItemIndex;
if(NavigationContext.QueryString.Contains("goto"))
{
strItemIndex=NavigationContext.QueryString["goto"].ToString();
pivotControl.SelectedIndex = Convert.ToInt32(strItemIndex);
}
base.OnNavigatedTo(e);
}
编辑
在您的 xaml 中进行更改
Make changes in your xaml
<Grid x:Name="LayoutRoot" Background="Transparent">
<!--Pivot Control-->
<controls:Pivot Title="MY APPLICATION" x:Name="pivotControl">
<!--Pivot item one-->
<controls:PivotItem Header="one">
<Grid/>
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem Header="two">
<Grid/>
</controls:PivotItem>
</controls:Pivot>
</Grid>
这篇关于如何导航到 Windows Phone 中的某个 Pivot 页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!