Fabrizio La Racca
Fabrizio La Racca

Reputation: 75

.NET MAUI: wrong namespace in new ContentPage

I have created a MAUI App with 'KnifeMaui' namespace.

Now when I add a new element->ContentPage it is generated with 'MauiApp1' namespace.

If I try to change it to 'KnifeMaui' I get an error for method InitializeComponent() (the name does not exists in the current context).

This is problem when in AppShell.xaml I try to set up an xmlns and it doesn't find KnifeMaui.Views.

I have looked in project properties but I haven't found any MauiApp1 reference.

Has anyone encountered this problem and fixed it?

Upvotes: 1

Views: 1169

Answers (2)

FreakyAli
FreakyAli

Reputation: 16449

To fix this you need to make changes in XAML and C# side of things, since we have to link the two partials to each other.

In XAML side look for:

    x:Class="YourNameSpace.YourClassName"

On your Code-Behind C#:

namespace YourNameSpace;

public partial class YourClassName : Shell (Shell ContentPage whatever)
{

Upvotes: 1

Gerald Versluis
Gerald Versluis

Reputation: 34013

This is currently a bug in Visual Studio 17.4 preview 1. The MauiApp1 namespace should’ve been replaced with the project name.

As suggested by others there is an easy fix by just renaming that namespace to whatever it should be in your project. Hopefully the bug wil be fixed soon. You can follow the progress here: https://developercommunity.visualstudio.com/t/Problem-with-adding-new-page-to-project/10118293

Upvotes: 1

Related Questions