I know how to navigate from one pivot item to another, within the pivot page, but what if the navigation is initiated from another page entirely?
UPDATE:
Here is the solution I used, based on the answer from Matt Lacey:
From button click event on MainPage:
private void button_Click(object sender, RoutedEventArgs e)
{
string parameter = "myPivotItem1";
NavigationService.Navigate(new Uri(string.Format("/MyPivotPage.xaml?parameter={开发者_JAVA技巧0}", parameter), UriKind.Relative));
}
Overrode OnNavigatedTo for the pivot page, and extracted the querystring:
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
string newparameter = this.NavigationContext.QueryString["parameter"];
if (newparameter.Equals("myPivotItem1"))
{
myPivotControl.SelectedItem = myPivotItem1;
}
else if (newparameter.Equals("myPivotItem2"))
{
myPivotControl.SelectedItem = myPivotItem2;
}
}
You can set the SelectedIndex
to the index of the item you want.
Be careful of the delayed loading of item though.
Update:
On the first page, pass an indicator of which pivotItem to display in the querystring** of the page you are navigating to.
In the OnNavigatedTo event on the page, containing the pivot, create a handler for the Loaded event of the Pivot and use that to set the SelectedIndex.
** Other ways of doing this are available.
精彩评论