Navigating to another shell page outside AppShell in .Net MAUI

GloryDiv 31 Reputation points
2022-04-22T13:53:30.683+00:00

I have a project with 5 Bottomtabs. The first tab shows a CollectionView of items users have to select. After selecting an item i want the user to be navigated onto another page, shellPage, which has 3 top tabs. Navigating onto a single Contentpage works fine but another shell or even a TabbedPage is not working. Below are the errors or feedbacks i got solving the problem of navigating onto the other shellPage.

The efforts i made
I wrapped AppShell in a NavigationPage as MainPage =new NavigationPage( new AppShell());

  1. using `App.Current.MainPage.Navigation.PushModalAsync(new anotherShellPage());' or Shell.Current.Navigation.PushAsync($"{typeof(anotherShellPage)}"); to
    navigate.
    error : System.InvalidCastException: 'Specified cast is not valid.'
  2. using Navigation.PushAsync(new NavigationPage(new anotherShellPage())); or App.Current.MainPage.Navigation.PushModalAsync(new anotherShellPage());
    error :Java.Lang.IllegalArgumentException: 'DrawerLayout must be measured with MeasureSpec.EXACTLY.'. Here the new AppShell was without new NavigationPage() wrap.

What seems to be working
3. Using ** App.Current.MainPage.Navigation.PushAsync(new anotherShellPage());** navigates alright. But when the backbutton is pressed to navigate back to the ShellApp i get this error :Java.Lang.IllegalArgumentException: 'No view found for id 0x3 (unknown) for fragment ShellSectionRenderer{cce9fa} (143e32bb-f7d2-4698-bfcd-2d94c8d7d6bc id=0x3)'

  1. using App.Current.MainPage.Navigation.PushModalAsync(new anotherShellPage()); also navigates but before navigating the navigation bar of the AppShell pulls down before navigating and after pressing the back button app closes without moving back to the AppShell/root page.
  2. I aslso tried to create <tab> ** 3 top pages here ** </tab> outside the main <TabBar> in the AppShell.xaml so i forget about the anotherShellPage. This also navigates alright but the back buttom closes the app.

I just want to be able to move from one shellPage to another shellPage or TabbedPage and back. In real world an app with navigation like Besoccer app. Thank you.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,750 questions
{count} votes

1 answer

Sort by: Most helpful
  1. James Montemagno 1 Reputation point
    2022-04-25T02:28:57.597+00:00

    You will want to use Shell navigation which is based on URI's https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/navigation

    and also here is a video I did on it https://www.youtube.com/watch?v=8iYpLMKE_ws