是否可以通过按钮单击事件导航到枢轴控制页面

我正在尝试创建一个wp7枢轴控制应用程序。 单击第一页中的按钮,我想导航到另一个已经是枢轴页面的页面。 可能吗 ?

例如,您有以下Pivot控件的定义:

           

然后,您可以在按钮单击事件处理程序中使用此代码转到示例OtherSettings:

 SettingsPivot.SelectedItem = OtherSettings; 

像这样做

 NavigationService.Navigate(new Uri("/Pages/Page.xaml?PivotMain.SelectedIndex = 0", UriKind.Relative)); 

SelectedIndex可以是任何因素,具体取决于您拥有的枢轴项目数

以下是您可以导航到另一个页面的方法,如果它是一个数据透视页面则无关紧要:

 NavigationService.Navigate(new Uri("/SettingsPivot.xaml", UriKind.Relative)); 

如果您尝试导航到另一个pivotitem,则需要执行以下操作

 int i=1; //This is the index of the pivotitem you would like to navigate to PivotMenuName.SelectedIndex = i; 

听起来你想要第二段代码。 如果您的Pivot有2个项目(比如item1,item2),那么要从item1导航到item2,您将使用:

 MyPivot.SelectedIndex = IndexOfPageToGoTo; 

看看这个演示它的快速示例。

http://dl.dropbox.com/u/129101/WindowsPhonePivotApplication1.zip

也就是说,如果您将它用于“向导”样式的应用程序,则不建议这样做。 见http://timheuer.com/blog/archive/2010/08/13/windows-phone-panorama-versus-pivot-ux-guidelines.aspx

 NavigationService.Navigate(new Uri("MainPage.xaml?PivotMain.SelectedIndex = 0", UriKind.Relative)); 

index变为0-1-2-3 …写下你要导航的那个。

如果您已动态创建透视项,则可以使用以下简单代码:

 // This find object named as customName object pvtItm = pivotName.FindName("customName"); // If this object has type of PivotItem, navigate to it if (pvtItm is PivotItem) { pivotName.SelectedItem = pvtItm; }