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?
2 Answers
1
votes
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>
Pivot
control itself is a navigation control, you just need to tap its header, then it will navigate to the specific content. – Xie Steven