【问题标题】:Can in I navigate to pivot item from another xaml page in windows phone 7?我可以从 Windows Phone 7 中的另一个 xaml 页面导航到数据透视项目吗?
【发布时间】:2012-04-12 10:11:13
【问题描述】:

我尝试使用此代码导航到另一个页面中的数据透视项,但它仍然无法正常工作

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

谁能帮帮我?

感谢之前

【问题讨论】:

    标签: c# silverlight windows-phone-7 xaml pivot


    【解决方案1】:

    我已经描述了如何在这里轻松完成(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);
    }
    

    【讨论】:

    • 我已经尝试过了,但一点也不好,但感谢您尝试帮助我:)
    • 到底是什么问题?如果您从 codeplex 下载示例,它不会像我说的那样工作吗?
    【解决方案2】:

    这里有一个解决方案。只需将以下代码添加到目标页面:

    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;
                }
            }
        }
    }
    

    【讨论】:

      【解决方案3】:
      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);
      }
      

      请注意,myPivot0 是您的枢轴的名称(根据您的枢轴名称更改它)。然后,导航:

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

      其中ContactP.xaml 包含枢轴。

      【讨论】:

        【解决方案4】:

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

        【讨论】:

          【解决方案5】:

          您应该能够在 OnNavigatedTo 方法中设置枢轴的选定索引。也可以看看http://christian-helle.blogspot.co.uk/2011/02/working-around-pivot-selectedindex.html

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2011-06-26
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多