0
votes

I'm trying to navigate to a specific page in a UWP app. I've used Windows Template Studio and created 5 pages as part of a Pivot Control.

I want to navigate to the "Settings" page if it a First Time use of the program. My logic can identify the first time use, but I cannot figure out how to navigate to the correct page.

Here is my 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>

And in my code behind:

 if (isFirstTime)
        {
           // this.Frame.Navigate(SettingsPage);

            NavigationService.Navigate(new Uri("/PivotPage.xaml?item=4", UriKind.RelativeOrAbsolute));
        }

The error Im getting is : Argument 1: cannot convert from 'System.Uri' to 'System.Type'

1

1 Answers

0
votes

In PivotPage.xaml set the Name for the Pivot control and the PivotItem, that displays SettingsPage:

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Pivot Name="MainPivot" x:Uid="PivotPage">
        ...
        <PivotItem Name="SettingsPivotItem" x:Uid="PivotItem_Settings">
            ...
        </PivotItem>
    </Pivot>
</Grid>

Use the names of the controls in code-behind to make your PivotItem the selected one:

if (isFirstTime)
    MainPivot.SelectedItem = SettingsPivotItem;