Navigating to another shell page outside AppShell in .Net MAUI

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());
- 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.' - 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)'
- 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.
- 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.
@ JessieZhang-2116 hi. My whole problem is to navigate from one shell page onto another shell page with a button click
Codes from App.xaml.cs
Codes from AppShell.xaml.cs
Codes from AppShell.xaml
Codes from MondayPage.xaml.cs
Here MondayPage has just a button to navigate unto AnotherShellPage
AnotherShellPage is a shell page with both button and top tabs for different activites. I've tried many ways a few are those i have commented.
Do you mean you want to navigate to another app from current app ?If yes, you can use dependency injection to achieve this.
No not a different app. Am talking about same app
Could you please share a demo?
That's same as the codes I have posted above.
Sign in to comment
1 answer
Sort by: Most helpful
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
@James Montemagno Thank you for your answer . Inside MyCofeeApp navigating unto AddMyCoffePage is perfect since it is a single page(ContentPage). Assuming AddMyCoffePage is another shellPage / TabbedPage thats where my problem comes. I just changed AddMyCoffePage to a Shell and i got this error.Java.Lang.IllegalArgumentException: 'DrawerLayout must be measured with MeasureSpec.EXACTLY.'. And under what i stated above as What seems to be working after navigating onto the second shell page the Navigation.NavigationStack value is 1 so u cant go back and a whole lot if you still work around that. Results from .Net Maui is different and better than that of Xamarin anyway.
Sign in to comment