导航到特定的 PivotItem [英] Navigation to a Specific PivotItem

查看:23
本文介绍了导航到特定的 PivotItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击主页上的图像时,如何导航到 Pivot-Page 的特定 Pivot-item?

How do I navigate to a specific Pivot-item of Pivot-Page when I tap an Image on Main-Page ?

主页上的图像的 XAML 代码如下

The XAML codes are following for Image on Main Page

 <Image  Source="Assets/5.jpg" Stretch="UniformToFill" Height="150" Width="150" Margin="12,12,0,0"/>

Pivot-Page 的代码如下

And the code for Pivot-Page is following

<phone:PivotItem Header="fifth">
    ..........         
    ..........                      
        </phone:PivotItem>

当我点击主页上的图像时,我想导航到第五个枢轴项..

I want to navigate to the fifth Pivot-Item when I tap the Image on Main Page..

推荐答案

您可能希望在导航参数中发送要导航到的 PivotItem 的索引(如果您的 Pivot HAS static PivotItems)

You may want to send in your navigation args the index of the PivotItem you want to navigate to (if your Pivot HAS static PivotItems)

所以你想导航到第五个 PivotItem,那么你可能想传递一个带有 PivotItem 索引(4)的导航参数.在您的 PivotItem 页面中,您将从传递的参数中获取索引并使用 SelectedIndex

so you want to navigate to the FIFTH PivotItem, then you may want to pass a navigation parameter with the index of PivotItem (which is 4). In your PivotItem page, you will get the index from the passed param and select the PivotItem using the property SelectedIndex

例如,您的 Pivot 包含在 PivotPage.xaml 中,那么您可能希望像这样导航到该页面(您将导航调用添加到图像点击当然是事件处理程序):

For example, your Pivot is contained in PivotPage.xaml, then you may want to navigate to that page like so (you add the navigation call to the image tap event handler of course):

this.NavigationService.Navigate(new Uri("/PivotPage.xaml?item=4", UriKind.RelativeOrAbsolute));

item=4 是你的导航参数

然后在您的 PivotPage.xaml 代码隐藏中,添加对 PhoneApplicationPageOnNavigateTo() 方法的覆盖,如下所示:

Then in your PivotPage.xaml code-behind, add an override to OnNavigateTo() method of PhoneApplicationPage, like so:

protected override void OnNavigatedTo(NavigationEventArgs e)
{
        base.OnNavigatedTo(e);
        if (NavigationContext.QueryString.ContainsKey("item"))
        {
            var index = NavigationContext.QueryString["item"];
            var indexParsed = int.Parse(index);
            Pivot.SelectedIndex = indexParsed;
        }
}

这篇关于导航到特定的 PivotItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆