MAUI 项目,无法添加新页面
MAUI project, cannot add a new Page
我正在试用 MAUI,但 运行 遇到了一个奇怪的错误。它不会让我添加新页面,每次我尝试这样做时,构造函数中的 InitializeComponent
都会给我一个错误:
The name 'InitializeComponent' does not exist in the current context
我在 C# 代码和 XAML 代码中添加了 Microsoft.Maui.Controls
。
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
有人知道在这里做什么吗?
将新的 MAUI 页面添加到项目后,我遇到了同样的错误。解决方案是从 .csproj
文件中删除以下行:
<ItemGroup>
<MauiXaml Remove="Pages\Page1.xaml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Pages\Page1.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
然后删除 Page1.xaml.cs
文件中的 InitializeComponent();
语句,重建项目,最后将 InitializeComponent();
添加回 Page1.xaml.cs
。
问题是 Maui SourceGen 无法为 Page1.xaml.cs
文件生成 Page1.xaml.sg.cs
文件。
让我知道此解决方案是否适合您。
这已经回答但发现了这个。在 Microsoft Visual Studio 社区
2022 (64-bit) - Preview
Version 17.1.0 Preview 1.1
。我添加了这个
.NET MAUI Project and Item Templates from Visual Studio Marketplace
https://marketplace.visualstudio.com/items?itemName=egvijayanand.maui-item-templates
然后像正常添加....和select MAUI
我正在试用 MAUI,但 运行 遇到了一个奇怪的错误。它不会让我添加新页面,每次我尝试这样做时,构造函数中的 InitializeComponent
都会给我一个错误:
The name 'InitializeComponent' does not exist in the current context
我在 C# 代码和 XAML 代码中添加了 Microsoft.Maui.Controls
。
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
有人知道在这里做什么吗?
将新的 MAUI 页面添加到项目后,我遇到了同样的错误。解决方案是从 .csproj
文件中删除以下行:
<ItemGroup>
<MauiXaml Remove="Pages\Page1.xaml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Pages\Page1.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
</ItemGroup>
然后删除 Page1.xaml.cs
文件中的 InitializeComponent();
语句,重建项目,最后将 InitializeComponent();
添加回 Page1.xaml.cs
。
问题是 Maui SourceGen 无法为 Page1.xaml.cs
文件生成 Page1.xaml.sg.cs
文件。
让我知道此解决方案是否适合您。
这已经回答但发现了这个。在 Microsoft Visual Studio 社区
2022 (64-bit) - Preview
Version 17.1.0 Preview 1.1
。我添加了这个
.NET MAUI Project and Item Templates from Visual Studio Marketplace
https://marketplace.visualstudio.com/items?itemName=egvijayanand.maui-item-templates
然后像正常添加....和select MAUI