Home > front end >  Can't navigate to the MainWindow
Can't navigate to the MainWindow

Time:08-19

When I navigate to another page in the NavigationView, it works, but when I try to return to the MainWindow by clicking on the selected item, it doesn't work.

Screenshot of the thrown exception: Screenshot of the thrown exception

Snippet

private void NavigationViewItem_Tapped(object sender, Microsoft.UI.Xaml.Input.TappedRoutedEventArgs e)
{
    rootframe.Navigate(typeof(MainWindow));
}

CodePudding user response:

You cannot navigate to the main window. Frame.NavigateTo() actually expects a "Page-derived data type". The documentation is especially muddy about it, but it finally states:

Causes the Frame to load content represented by the specified Page-derived data type,...

So, you need to create a new class deriving from Page, put your content there and that's it.

  • Related