我正在尝试导航到UWP应用中的特定页面。我使用了Windows Template Studio并创建了5个页面作为Pivot Control的一部分。
如果是首次使用该程序,我想导航到“设置”页面。我的逻辑可以识别第一次使用,但我无法弄清楚如何导航到正确的页面。
这是我的PivotPage xaml:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Pivot x:Uid="PivotPage">
<PivotItem x:Uid="PivotItem_Main">
<Frame>
<views:MainPage/>
</Frame>
</PivotItem>
<PivotItem x:Uid="PivotItem_Patient">
<Frame>
<views:PatientPage/>
</Frame>
</PivotItem>
<PivotItem x:Uid="PivotItem_Templates">
<Frame>
<views:TemplatesPage/>
</Frame>
</PivotItem>
<PivotItem x:Uid="PivotItem_PracticeInfo">
<Frame>
<views:PracticeInfoPage/>
</Frame>
</PivotItem>
<PivotItem x:Uid="PivotItem_Settings">
<Frame>
<views:SettingsPage/>
</Frame>
</PivotItem>
</Pivot>
</Grid>
在我的代码背后:
if (isFirstTime)
{
// this.Frame.Navigate(SettingsPage);
NavigationService.Navigate(new Uri("/PivotPage.xaml?item=4", UriKind.RelativeOrAbsolute));
}
我得到的错误是: 参数1:无法从'System.Uri'转换为'System.Type'
答案 0 :(得分:0)
在 PivotPage.xaml 中设置Name
控件的Pivot
和显示PivotItem
的{{1}}:
SettingsPage
使用代码隐藏中控件的名称使<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Pivot Name="MainPivot" x:Uid="PivotPage">
...
<PivotItem Name="SettingsPivotItem" x:Uid="PivotItem_Settings">
...
</PivotItem>
</Pivot>
</Grid>
成为选定的控件:
PivotItem