Home > Software engineering >  .NET MAUI ShellContent not found
.NET MAUI ShellContent not found

Time:12-15

I have added a TabBar to my Shell:

<Application.MainPage>
    <Shell>
    ...
    <TabBar x:Name="PhoneTabs">
        <Tab Title="Home" Icon="tab_home.png">
            <ShellContent ContentTemplate="{DataTemplate page:MainPage}"/>
        </Tab>
    </TabBar> 
    ...
</Shell>

App.cs

public partial class App : Application
{
    public App()
    {
        InitializeComponent();
    }
}

And I get this error:

App.xaml(62,35): XamlC error XFC0000: Cannot resolve type ":MainPage".

MainPage exists and was okay, before I changed the layout to a Shell (use the official MAUI Xaml Template form VS 2022 Preview). Code Before:

protected override Window CreateWindow(IActivationState activationState) =>
    new Window(new NavigationPage(new MainPage())) { Title = "My App" };

Already tried clean and build.

CodePudding user response:

[Adding this Community answer, so it is clear the question was resolved.]

OP (Original Poster) reports in a comment above that they solved the problem by adding a namespace declaration.

In xaml, part of the declaration at the top of the file:

xmlns:page="clr-namespace:XXXX    <-- replace XXXX with your namespace.

Then when defining an element in XAML from that namespace:

<page:YourElementName ... />

Replace "page" with whatever "nickname" you want.

  • Related