Windows Template Studio - UWP- Navigation to Uri



我有一个UWP应用程序,并且使用了Windows Template Studio。这使用实现帧导航的导航服务。我的 UI 包含一个透视控件,每个透视项都包含一个页面。有没有办法通过特定页面上的按钮单击等事件导航到特定的透视项?

可能是

我们希望将用户引导到特定控件或向他们提供更多信息的情况。假设有一个主页,我们告诉用户有新的东西,但它可能在其中一个透视页面中。用户只需单击按钮,即可将他们带到特定的透视项或透视项中的其他特定控件。不知道如何更好地解释这一点。

如果是这样,您必须自己编码才能满足您的要求。

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

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>

您可以通过查询字符串传递信息来执行此操作。 在按钮单击事件中:

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

这个答案可能会对你有所帮助

相关内容

最新更新