Windows Template Studio - UWP- 导航到 Uri

Windows Template Studio - UWP- Navigation to Uri

我有一个 UWP 应用程序并使用了 Windows Template Studio。这使用实现框架导航的 NavigationService。我的 UI 包括一个 Pivot 控件,每个 Pivot 项目都包括一个页面。有没有一种方法可以通过在特定页面上单击按钮之类的事件导航到特定的 Pivot 项目?

您可以通过查询字符串传递信息来做到这一点。 在您的按钮点击事件中:

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

This answer may help you

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.

如果是这样,您将不得不自己编写代码来实现您的要求。

例如,您可以使用一些简单的代码来执行以下操作:

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>