Issue
I'm trying out MAUI and I've ran into a weird bug. It won't let me add a new page, every time i try to do so the InitializeComponent in the constructor gives me an error saying "The name 'InitializeComponent' does not exist in the current context" I've added Microsoft.Maui.Controls in the C# code and xmlns="http://schemas.microsoft.com/dotnet/2021/maui" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" in the XAML code.
Does anyone know what to do here?
Solution
I got the same error after adding new MAUI page to the project. The solution was to remove the following lines from .csproj
file:
<ItemGroup>
<MauiXaml Remove="Pages\Page1.xaml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Pages\Page1.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
Then remove InitializeComponent();
statement in Page1.xaml.cs
file, rebuild the project and finally add InitializeComponent();
back to Page1.xaml.cs
.
The problem is that Maui SourceGen was not able to generate Page1.xaml.sg.cs
file for the Page1.xaml.cs
file.
Let me know if this solution works for you.
Answered By - Tonven
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.