I have a UWP application and have used the Windows Template Studio. This uses a NavigationService which implements Frame Navigation. My UI includes a Pivot control and each pivot item includes a page. Is there a way to navigate to a specific Pivot item through an event like button click on a specific page?
Asked
Active
Viewed 168 times
0
-
Actually, I did not understand why did you want to navigate to a specific pivot item through a button click? The `Pivot` control itself is a navigation control, you just need to tap its header, then it will navigate to the specific content. – Xie Steven Aug 09 '18 at 06:47
-
It could be situations where we want to guide a user to a specific control or provide them more information. Let's say there is a home page and we tell users that there is something new but it could be in one of those pivot pages. The user just click on the button which takes them to a specific pivot item or possibly some other specific control within the Pivot Item. Not sure how to explain this better. – RamyaN Aug 09 '18 at 09:36
2 Answers
1
It could be situations where we want to guide a user to a specific control or provide them more information. Let's say there is a home page and we tell users that there is something new but it could be in one of those pivot pages. The user just click on the button which takes them to a specific pivot item or possibly some other specific control within the Pivot Item. Not sure how to explain this better.
If so, you would have to code by yourself to achieve your requirement.
For example, you could use some simple code to do it like the following:
private void Button_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
var query = "your parameter"; // you need to specify the query parameter by the different situation
switch (query)
{
case null: pivotPage.SelectedIndex = 0; break;
case "MainPage": pivotPage.SelectedIndex = 0; break;
case "Page1": pivotPage.SelectedIndex = 1; break;
default: pivotPage.SelectedIndex = 0; break;
}
}
<Grid>
<Pivot x:Name="pivotPage" >
<PivotItem Header="MainPage">
<Frame>
<views:MainPage/>
</Frame>
</PivotItem>
<PivotItem Header="Page1">
<Frame>
<views:BlankPage1></views:BlankPage1>
</Frame>
</PivotItem>
</Pivot>
<Button Content="Navigate to Page1" Click="Button_Click"></Button>
</Grid>

Xie Steven
- 8,544
- 1
- 9
- 23
0
You can do this by passing information through Query String. Inside your button click event:
this.NavigationService.Navigate(new Uri("/PivotPageAddress.xaml?item=2", UriKind.RelativeOrAbsolute));

Hannan Ayub
- 378
- 2
- 15
-
As I mentioned it uses Frame based Navigation as in the link below. https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.frame.navigate There is no overload which accepts a Uri. – RamyaN Aug 08 '18 at 12:55