-1

I have application based on Shell. Application contains pages with tabs which are deffined in Shell. Everything works properly and correctly.

I need create second level page with tabs whitch contains options for return to previous page. In the case of standard "ContentPage", "Routing.RegisterRoute" and "Shell.Current.GoToAsync" it is no problem. However, if I create a TabbedPage like this, my application ends with exception:

0xFFFFFFFFFFFFFFFF in Android.Runtime.JNIEnv.monodroid_debugger_unhandled_exception

I am aware of this information:

TabbedPage is incompatible with .NET MAUI Shell apps, and an exception will be thrown if you attempt to use TabbedPage in a Shell app.

  1. However, I am not sure if this also applies to the second level page, or only to pages that are directly referenced in Shell.
  2. How can I create second level page with tabs?

Is there anyone who has encountered a similar problem, or someone who can give me advice?

Thanks a lot

Jozef
  • 13
  • 6
  • 1
    I mean you've just posted yourself an answer . ***TabbedPage is incompatible with .NET MAUI Shell apps, and an exception will be thrown if you attempt to use TabbedPage in a Shell app.*** this tells you everything you need to know. TabbedPages are not yet in `.net MAUI` so don't use them. If you want navigation use `MVVM` pattern with commands with `buttons` or `tap gesture recognizer`. – ThisQRequiresASpecialist Dec 14 '22 at 10:38
  • With that, you can create custom navigations as you like. Just tell the command what you want to do. e.g. `ICommand NextPageCommand = new Command( async () => await Shell.Current.GoToAsync(registered page));` Further if you're using `flyout` you and you want custom `button` to open flyout do `ICommand OpenFlyoutCommand = new Command( () => Shell.Current.FlyoutIsPressented = true);`. Done you now have all the tools to make custom navigation and anything else possible with `Shell App`. Happy Coding – ThisQRequiresASpecialist Dec 14 '22 at 10:41
  • [MVVM](https://learn.microsoft.com/en-us/xamarin/xamarin-forms/enterprise-application-patterns/mvvm) for Xamarin. I personally use all the above in `Xamarin.Forms` to create custom navigation and make it look customized and unique. – ThisQRequiresASpecialist Dec 14 '22 at 10:43
  • 1
    The documentation clearly states that TabbedPage is incompatible with Shell, so trying it anyway is in vain. You could try something like Sharpnado.Tabs instead. – Julian Dec 14 '22 at 12:42
  • FWIW (in-depth knowledge required - this is not a recommendation, just FYI): OR don't use AppShell. Find the line `MainPage = new AppShell();`. REPLACE that with `MainPage = new NavigationPage();`. HOWEVER then you can't use AppShell's Navigation; instead use `NavigationPage` class' navigation methods. This is what everyone did in Xamarin.Forms, (and some of us still do), before `AppShell` was invented. – ToolmakerSteve Dec 15 '22 at 01:39

2 Answers2

1

Using shell, you are limited to content pages. Navigating to such page is not a problem. Calling GoToAsync will give you the "second layer" you request.

The more interesting part is how to implement tab control, so you have tabs in that ContentPage.

One way to solve this is by using BindableLayouts.

(Here is a good example: https://dev.to/davidortinau/making-a-tabbar-or-segmentedcontrol-in-net-maui-54ha)

You can make really neat UI with this. It will be worth your time.

Ask if you have any questions.

H.A.H.
  • 2,104
  • 1
  • 8
  • 21
  • Thank you very much for your answers. I am currently considering what is the best option: 1. custom TabView and update all screens that have tabs 2. Update the entire application without Shell. I am not sure which option will bring me more problems and which will be more complicated. – Jozef Dec 16 '22 at 09:50
  • @Jozef It does not matter, really. Shell saves me time, and for that time I pay with loss of flexibility. I haven't found a problem that can't be solved using shell. All the tools are there. Good luck with your app. – H.A.H. Dec 17 '22 at 17:13
0

You can combine TabbedPage, FlyoutPage and NavigationPage instead of shell if you really want to create second level page with tabs. Obviously shell is based on flyouts and tabs, so if you use FlyoutPage and TabbedPage alone in your project, it will be more flexible and troublesome than the shell.

These are the documents about the specific use of FlyoutPage and TabbedPage, you can refer to them if you need: https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pages/flyoutpage?view=net-maui-7.0 and https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pages/navigationpage?view=net-maui-7.0.

Hope this will help you.

  • Thank you very much for your answers. I am currently considering what is the best option: 1. custom TabView and update all screens that have tabs 2. Update the entire application without Shell. I am not sure which option will bring me more problems and which will be more complicated. – Jozef Dec 16 '22 at 09:50
  • @Jozef If you want to custom the tabview, this link can provide specific steps for customing renderer in Maui:https://github.com/dotnet/maui/wiki/Using-Custom-Renderers-in-.NET-MAUI. And if you want to take my advice, you should use "MainPage=new NavigationPage(new Page1())" in AppShell.cs as mentioned and then use navigation methods to navigate. – Hongxin Sui-MSFT Dec 23 '22 at 05:31
  • If you think my solution works, you may consider marking my answer. Thanks. – Hongxin Sui-MSFT Dec 29 '22 at 02:07