简体   繁体   English

我可以在Windows Phone 7中导航到另一个xaml页面的数据透视表吗?

[英]Can in I navigate to pivot item from another xaml page in windows phone 7?

I try this code to navigate to pivotitem in another page, but it's still not work 我尝试使用此代码导航到另一个页面中的ivotitem,但仍然无法正常工作

private void Nada1_Click(object sender, RoutedEventArgs e)
    {
        NavigationService.Navigate(new Uri("/Nada.xaml?PivotNada.SelectedIndex=0", UriKind.Relative));
    }

Can anyone help me ? 谁能帮我 ?

Thanks before 之前感谢

I have described how i can be easily done here (sample project at http://wp7pivottest.codeplex.com ) http://invokeit.wordpress.com/2012/04/01/navigate-to-selected-pivot-item-wpdev-wp7dev/ 我已经描述了如何在这里轻松完成工作(示例项目位于http://wp7pivottest.codeplex.comhttp://invokeit.wordpress.com/2012/04/01/navigate-to-selected-pivot-item- wpdev-wp7dev /

public enum PivotDef
{
   One,
   Two,
   Three,
   Four,
}

public static PivotDef SelectedPivot;

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
   switch (SelectedPivot)
   {
      case PivotDef.One:
         this.pvtControl.SelectedItem = this.pvt1;
         break;

      case PivotDef.Two:
         this.pvtControl.SelectedItem = this.pvt2;
         break;

      case PivotDef.Three:
         this.pvtControl.SelectedItem = this.pvt3;
         break;

      case PivotDef.Four:
         this.pvtControl.SelectedItem = this.pvt4;
         break;
   }

   base.OnNavigatedTo(e);
}

Here is a solution for you. 这是为您提供的解决方案。 Just add the following code to destination page: 只需将以下代码添加到目标页面:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
    if (NavigationContext.QueryString.ContainsKey("PivotNada.SelectedIndex"))
    {
        int selectedIndex = -1;
        if(int.TryParse(NavigationContext.QueryString["PivotNada.SelectedIndex"].ToString(), out selectedIndex))
        {
            if(selectedIndex != -1)
            {
                pivot.SelectedIndex = selectedIndex;
            }
        }
    }
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
  string strItemIndex;
  if (NavigationContext.QueryString.TryGetValue("goto", out strItemIndex))
  {
    myPivot0.SelectedIndex = Convert.ToInt32(strItemIndex);
  }
  base.OnNavigatedTo(e);
}

Note that myPivot0 is the name of your pivot (change it based on your pivot name). 请注意, myPivot0是您的数据透视表的名称(请根据您的数据透视表名称进行更改)。 Then, navigate: 然后,浏览:

NavigationService.Navigate(new Uri("/ContactP.xaml?goto=0", UriKind.RelativeOrAbsolute));

where ContactP.xaml contains the pivots. 其中ContactP.xaml包含枢轴。

将该索引值作为查询字符串传递,然后更新onNNavigatedTo函数中的ivot.selectedindex值

You should be able to set the selected index of the piviot in the OnNavigatedTo method. 您应该能够在OnNavigatedTo方法中设置piviot的选定索引。 Have a look at http://christian-helle.blogspot.co.uk/2011/02/working-around-pivot-selectedindex.html too. 也可以看看http://christian-helle.blogspot.co.uk/2011/02/working-around-pivot-selectedindex.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM