Reputation: 11
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:
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;
}
}
Upvotes: 1
Views: 775
Reputation: 11
I'm facing the same issue: after hours I found your post and then this other one with possible solution: TabbedPage is not compatible with shell app. This explains why in my app i have error while in test app (which is not shell app) tabbed page works. Following the link: C# MAUI app - Java.Lang.IllegalArgumentException: No view found for id 0x7f080147 on Android
Upvotes: 0