Navigate to a specific PivotItem item

How to go to a specific pivot element of a summary page element when I click on the image on the main page?

XAML codes follow for the image on the main page

<Image Source="Assets/5.jpg" Stretch="UniformToFill" Height="150" Width="150" Margin="12,12,0,0"/> 

And the code for the pivot page is as follows

 <phone:PivotItem Header="fifth"> .......... .......... </phone:PivotItem> 

I want to go to the fifth rotary element when I touch the image on the main page.

+4
source share
2 answers

Rotation control has properties such as SelectedItem or SelectedIndex that you can configure for this.

 <phone:Pivot x:Name="pvControl"> <phone:PivotItem x:Name="piFive" Header="fifth"> .......... .......... </phone:PivotItem> pvControl.SelectedItem = piFive; 
+7
source

You might want to send the PivotItem index you want to go to in your navigation pointer (if your Pivot HAS static PivotItem s)

so you want to go to FIFTH PivotItem , then you may need to pass the navigation parameter with the PivotItem index (which is 4). On the PivotItem page PivotItem you get the index from the passed parameter and select PivotItem using the SelectedIndex property

For example, your Pivot contained in PivotPage.xaml , then you may want to go to this page how it is done (you, of course, add a navigation call to the event handler with the image):

 this.NavigationService.Navigate(new Uri("/PivotPage.xaml?item=4", UriKind.RelativeOrAbsolute)); 

item=4 - your navigation parameter

Then, in the PivotPage.xaml code PivotPage.xaml add an override to the OnNavigateTo() method of PhoneApplicationPage , for example:

 protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); if (NavigationContext.QueryString.ContainsKey("item")) { var index = NavigationContext.QueryString["item"]; var indexParsed = int.Parse(index); Pivot.SelectedIndex = indexParsed; } } 
+7
source

Source: https://habr.com/ru/post/1501973/


All Articles