简体   繁体   中英

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

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/

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). Then, navigate:

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

where ContactP.xaml contains the pivots.

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

You should be able to set the selected index of the piviot in the OnNavigatedTo method. Have a look at http://christian-helle.blogspot.co.uk/2011/02/working-around-pivot-selectedindex.html too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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