我在 Xamarin.Forms 项目的页面中收到错误:"找不到类型 ",请验证您没有缺少程序集引用,并且已生成所有程序集引用"。
这是我收到错误的地方:
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
//Here
x:Class="FirstApp.Pages.ChatMenuPage"
xmlns:renderers="clr-namespace:MyProject.Renderers"
xmlns:custom="clr-namespace:FirstApp"
xmlns:renderer="clr-namespace:FirstApp.Renderers"
NavigationPage.HasNavigationBar="False">
这是我的 XAML.CS 类:
using FirstApp.Services;
using Xamarin.Essentials;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace FirstApp.Pages
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class ChatMenuPage : ContentPage
{
InitializeComponent();
}
}
知道为什么会这样吗?
如果你在构造函数中有初始化组件,尝试重建项目,它对我有用。
必须在构造函数中使用 InitializeComponent
public partial class ChatMenuPage : ContentPage
{
public ChatMenuPage()
{
InitializeComponent();
}
}
您必须更改 .xaml 文件中的命名空间声明。
同样在Appshell.xaml更改中:
*xmlns:{XML namespace name}="clr-namespace:{.NET namespace}"*
教程创建 .NET MAUI 应用中的此链接也可能有所帮助: