Hello, Shell has special navigation method. Please refer this document:.NET MAUI Shell navigation.
Based on your environment, you can do following steps to fix this issue.
Firstly, please open your App.xaml.cs
, remove MainPage = new NavigationPage(new AppShell());
use MainPage = new AppShell();
directly like following code.
public App()
{
InitializeComponent();
MainPage = new AppShell();
// MainPage = new NavigationPage(new AppShell());
}
Second, open AppShell.xaml.cs
and register your page1 in the AppShell's constructor.
public AppShell()
{
InitializeComponent();
Routing.RegisterRoute("Page1", typeof(Page1));
}
Third, open your MainPage.xaml.cs
, find the ToolbarItem_Clicked
method, use await Shell.Current.GoToAsync("Page1");
to do navigation.
private async void ToolbarItem_Clicked(object sender, EventArgs e)
{
// Navigation.PushAsync(new Page1());
await Shell.Current.GoToAsync("Page1");
}
Best Regards, Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.