wbk727
wbk727

Reputation: 8408

How to navigate between pages inside Frame with a NavigationMenu

I have a project with 3 different pages to be eventually loaded within a Frame. In Frame1 how can I use a click event to navigate to a different page inside the Frame (i.e. Frame 3)?

XAML

<NavigationView Name="NavView">
    <Frame Name="myFrame"/>
</NavigationView>

XAML.CS

public MainPage()
    {
        this.InitializeComponent();
        myFrame.Navigate(typeof(Frame1));
    }

Frame1.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 1" FontSize="36"/>
    <Button Name="Button1" Text="Frame 3"/>
</Grid>

Frame2.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 2" FontSize="36"/>
</Grid>

Frame3.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 3" FontSize="36"/>
</Grid>

Upvotes: 0

Views: 593

Answers (1)

Nico Zhu
Nico Zhu

Reputation: 32775

In Frame1 how can I use a click event to navigate to a different page inside the Frame (i.e. Frame 3)?

Frame1.xaml

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <TextBlock Text="Frame 1" FontSize="36"/>
    <Button Name="Button1" Text="Frame 3"/>
</Grid>

You could add the Click event handler for Button then process the navigation in the code behind. If you want to navigate to Frame3 page from Frame1 page , you could use Frame1 page Frame property to navigate.

private void Button_Click(object sender, RoutedEventArgs e)
{
    Frame.Navigate(typeof(Frame3));
}

Upvotes: 1

Related Questions