I'm trying to go to another page when clicking a button. How could i do this (WinUI 3)

293 Views Asked by At

I'm trying to go to another page when clicking a button. How could i do this.

I tried using a NavigationViewItem but it didn't work.

1

There are 1 best solutions below

0
Junjie Zhu - MSFT On

The NavigationViewItem you posted is used in UWP.

If it is a WinUI3 project, then you need to refer to this document, use Navigate.

the relevant code samples are as follows.

xaml

<Button x:Name="myButton" Click="myButton_Click"/>

xaml.cs

private void myButton_Click(object sender, RoutedEventArgs e)
{

    Frame rootFrame = new Frame();          
    this.Content = rootFrame;

    rootFrame.Navigate(typeof(BlankPage1), null);
      
}