Cannot switch from one tabbed page to other tabbed page, NotSupportedExceptionUnable to find the default constructor on type Microsoft.Maui.Controls.Platform.FragmentContainer.Please provide the missing constructor.

dedeepya yarlagadda 50 Reputation points
2024-07-19T13:57:05.1266667+00:00

Hi

In my project the Main page is a tabbedpage and when we switch from the main page to another page which is also a tabbed page we are seeing System.NotSupportedException: 'Unable to find the default constructor on type Microsoft.Maui.Controls.Platform.FragmentContainer. Please provide the missing constructor.'

The tabbedpages internally have one more tabbed page to have tabs.

I am not able to find the place where this exception occurred and not able to fix it.

please let us know how to proceed and fix this.

Thanks


I am seeing the issue in Android and MAUI version is 8.

APP.XAML.CS

public App()
{
    InitializeComponent();
}
public App(IServiceProvider services ,DatabaseContext context)
{
    
    InitializeComponent();
    
    Services = services;
    CustomContentPageHandler.RegisterHandlers();
    
    MainPage = new NavigationPage(new MainTabs());

    
    DbContext = context;
    Routing.RegisterRoute(nameof(AboutPage), typeof(AboutPage));
}

Tab4

<?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:MediaShare.View"
            xmlns:locale="clr-namespace:MediaShare.Resources"
             x:Class="MediaShare.View.Tab4"
             Title="Tab4"           
             SelectedTabColor="{StaticResource  StatusBarColor}"
            UnselectedTabColor="{StaticResource Gray_text}"
            >
    <TabbedPage.Resources>
        <Style TargetType="views:MyDevices">
            <Setter Property="Title" Value="Roboto"/>
            
        </Style>
    </TabbedPage.Resources>
    
    <NavigationPage.TitleView>
        <Grid ColumnDefinitions="Auto,*">
            <views:CustomTitleBar x:Name="customTitleBar" Grid.Column="0"/>
            <Border Grid.Column="1" 
                x:Name="searchBorder"
                Style="{StaticResource SearchBorder}">
                <SearchBar Grid.Column="1"
                           x:Name="searchBarGrid" 
                           Style="{StaticResource Search}"
                           Text="{Binding SearchQuery, Mode=TwoWay}"
                           TextChanged="OnSearchTextChanged"
                           Placeholder="{x:Static locale:String_en.SearchDevice}"
                           />

            </Border>           
        </Grid>
    </NavigationPage.TitleView>
    <TabbedPage.ToolbarItems>
        <ToolbarItem IconImageSource="ic_search.svg"
                 Priority="2"
                 x:Name="searchMenu"
                 Clicked="OnSearchClicked"
                 Order="Primary"/>
       
        </TabbedPage.ToolbarItems>
     <views:Test1 x:Name="Test1"  Title="Test1"/>
    <views:Test2 x:Name="Test2" Title="Test2" IsEnabled="False"/>
    <views:Test3 x:Name="Test3" Title="Test3" IsEnabled="False" />
</TabbedPage>

Tab1

<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:views="clr-namespace:MediaShare.View"
             xmlns:locale="clr-namespace:MediaShare.Resources"
             x:Class="MediaShare.View.Tab1"
             Title="Tab1">
    <NavigationPage.TitleView>
        <Grid ColumnDefinitions="Auto,*">
            <views:CustomTitleBar x:Name="customTitleBar" Grid.Column="0" />
            <Border Grid.Column="1" 
                    x:Name="searchBorder"
                    Style="{StaticResource SearchBorder}">
                <SearchBar Grid.Column="1"
                               x:Name="searchBar" 
                               Style="{StaticResource Search}"
                               Text="{Binding SearchQuery, Mode=TwoWay}"
                               TextChanged="OnSearchTextChanged" 
                               CancelButtonColor="Black"
                               Unfocused="OnSearchBarUnFocused"
                               Placeholder="{x:Static locale:String_en.SearchFile}"
                               />
            </Border>
        </Grid>
    </NavigationPage.TitleView>
    <TabbedPage.ToolbarItems>
        <ToolbarItem IconImageSource="ic_search.svg"
                     Priority="2"
                     x:Name="searchMenu"
                     Clicked="OnSearchClicked"
                     Order="Primary"/>
        <ToolbarItem x:Name="infoMenu" IconImageSource="info_button.svg"
                     Priority="3"
                     Clicked="OnInfoClicked"      
                     Order="Primary"/>
        <ToolbarItem x:Name="InfoButton" Text="{x:Static locale:String_en.Info}" Order="Secondary" Priority="0" />
        <ToolbarItem x:Name="SelectionButton" Text="{x:Static locale:String_en.Select_All}" Order="Secondary" Priority="1" Command="{Binding SelectAllCommand}" IsEnabled="{Binding IsSelectionEnabled}"/>        
        <ToolbarItem x:Name="ClearButton" Text="{x:Static locale:String_en.ClearSelection}" Order="Secondary" Priority="2" Command="{Binding DeselectAllCommand}" IsEnabled="{Binding IsAnyItemSelected}"/>
    </TabbedPage.ToolbarItems>   
    <views:Tab1SubTabs x:Name="Tab1subtabsview" />
</TabbedPage>

Main TABS

<TabbedPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:views="clr-namespace:MediaShare.View"
            xmlns:android="clr-namespace:Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific;assembly=Microsoft.Maui.Controls"
             android:TabbedPage.ToolbarPlacement="Bottom"
             x:Class="MediaShare.View.MainTabs"           
             Title="MainTabs"
            IconImageSource="device.svg"
            BarBackground="#caeaff">
    <TabbedPage.Children>
        <NavigationPage x:Name="Tab1" Title="Tab1" IconImageSource="up_arrow.svg" BarBackgroundColor="#007acc" BarTextColor="White">
            <x:Arguments>
                <views:Tab1/>
            </x:Arguments>
        </NavigationPage>
        <NavigationPage x:Name="Tab2" Title="Tab2" IconImageSource="down_Arrow.svg" BarBackgroundColor="#007acc" BarTextColor="White">
            <x:Arguments>
                <views:Tab2/>
            </x:Arguments>
        </NavigationPage>
        <NavigationPage x:Name="Tab3" Title="Tab3" IconImageSource="history.svg" BarBackgroundColor="#007acc" BarTextColor="White" >
            <x:Arguments>
                <views:Tab3/>
            </x:Arguments>
        </NavigationPage>
        <NavigationPage x:Name="Tab4" Title="Tab4" IconImageSource="device.svg" BarBackgroundColor="#007acc" BarTextColor="White">
            <x:Arguments>
                <views:Tab4/>
            </x:Arguments>
        </NavigationPage>
    </TabbedPage.Children>
</TabbedPage>
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,594 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 32,386 Reputation points Microsoft Vendor
    2024-07-23T08:56:30.6233333+00:00

    Hello,

    Please modify the Tab1, Tab2, Tab3, Tab4, and make them derive from ContentPage instead of TabbedPage.

    I noticed that the MainTabs has four tabs, and each of them is type of NavigationPage which wrappers a TabbedPage (Tab1,Tab2,Tab3,Tab4).

    <TabbedPage.Children>
            <NavigationPage x:Name="Tab1" Title="Tab1" IconImageSource="up_arrow.svg" BarBackgroundColor="#007acc" BarTextColor="White">
                <x:Arguments>
                    <views:Tab1/>
                </x:Arguments>
            </NavigationPage>
    

    There are 2 issues.

    A TabbedPage should only be populated with NavigationPage and ContentPage objects. See NavigationPage - .NET MAUI | Microsoft Learn

    It's recommended that a NavigationPage should only be populated with ContentPage objects. See TabbedPage - .NET MAUI | Microsoft Learn

    Update


    I have main tabs and want subtabs inside that page please find the wireframe below and suggest what could be the right approach.

    For this, please use .NET MAUI Shell tabs, and you can set Bottom and top tabs

    Best Regards,

    Wenyan Zhang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.