0

I'm trying to create a TabbedPage view on the company app.

First of all, to assure evertything is working, I created a XAML ContentPage MyTabbedPage, and configured the Dependency Injection for it on the MauiProgram.cs just like on the other views

mauiAppBuilder.Services.AddSingleton<MyTabbedPage>();

On my main page, I navigate to it using a button that is binded to this command

[RelayCommand]
private async Task Create() => await _navigationService.NavigateToPage<MyTabbedPage>();

This is the NavigateToPage method on the _navigationService:

        public async Task NavigateToPage<T>(object? parameter = null) where T : Page
        {
            var toPage = ResolvePage<T>();

            if (toPage is not null)
            {
                //Subscribe to the toPage's NavigatedTo event
                toPage.NavigatedTo += PageNavigatedTo;

                //Get VM of the toPage
                var toViewModel = GetPageViewModelBase(toPage);

                //Call navigatingTo on VM, passing in the parameter
                if (toViewModel is not null)
                    await toViewModel.OnNavigatingTo(parameter);

                //Navigate to requested page
                await Navigation.PushAsync(toPage, true);

                //Subscribe to the toPage's NavigatedFrom event
                toPage.NavigatedFrom += PageNavigatedFrom;
            }
            else
                throw new InvalidOperationException($"Unable to resolve type {typeof(T).FullName}");
        }

And it works as expected.

But what I really need is a TabbedPage, so I change the ContentPage to a TabbedPage (on both the XAML and the xaml.cs files), and set the children of the TabbedPage, so the XAML is now this:

<?xml version="1.0" encoding="utf-8" ?>
<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:views="clr-namespace:MyApp.Pages"
             x:Class="MyApp.Pages.MyTabbedPage"
             Title="MyTabbedPage">

    <views:MyChildrenPage/>

</TabbedPage>

Now, when I press the button to navigate to it, I get the error:

Java.Lang.IllegalArgumentException: 'No view found for id 0x7f0a018b (CONFIDENTIALPATH/navigationlayout_toptabs) for fragment ViewFragment{a6b7d12} (fec1b5a7-e8fa-4129-a651-e8c4978783fb id=0x7f0a018b)'

*CONFIDENTIALPATH -> censored path with the name of the company's app.

I tried without the children, and also with a fresh ContentPage as a children, but the problem seems to be with the TabbedPage itself because I still get the same error.

Some information that might be useful:

  • I couldn't find anything about this error on the internet, besides the "same error" on other languages/frameworks, like this one. None of those were caused by tabs, and they also didn't help me understand the problem.
  • I'd like to avoid using Shell stuff if possible.
  • I'm following Microsoft's TabbedPage documentation.
  • I'm using MVVM, so the MyChildrenPage view has a binding with its ViewModel as follows
public partial class MyChildrenPage : ContentPage
{
    public MyChildrenPage()
    {
        InitializeComponent();

        //Done this way because TabbedPage will complain if the children has a constructor with 
        //parameters, even tho Microsoft tells us to use MVVM. How ironic huh?
        var viewModel = Application.Current.MainPage.Handler.MauiContext.Services.GetService<MyChildrenViewModel>();
        BindingContext = viewModel;
    }
}
  • Per [Navigate within a tab](https://learn.microsoft.com/en-us/dotnet/maui/user-interface/pages/tabbedpage?view=net-maui-7.0#navigate-within-a-tab), you may need wrap the `CotenPage`: MyChildrenPage within a `NaviagtionPage`. If that doesn't work, please help create [Minimal, Reproducible Example](https://stackoverflow.com/help/minimal-reproducible-example) via Github link. Thanks in advance! – Alexandar May - MSFT Apr 25 '23 at 07:46
  • 1
    @AlexandarMay-MSFT I don't think this is the problem, since the TabbedPage won't work even with no children on it at all, so I believe the error is before the "rendering" of the children. I'll try to create a small example and see if I get this error to trigger. – Fernando Lopes Apr 25 '23 at 12:10
  • Look forward to hearing from you! – Alexandar May - MSFT Apr 26 '23 at 07:51

0 Answers0