XAML 如何解决错误:未找到类型“”,请验证是否缺少程序集引用,

hec6srdp  于 2023-05-11  发布在  其他
关注(0)|答案(3)|浏览(329)

我在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(); 
    }
}

知道为什么会这样吗

qlzsbp2j

qlzsbp2j1#

如果你在构造函数中有InitializeComponent,尝试重建项目,它对我有效。

gk7wooem

gk7wooem2#

必须在构造函数中使用InitializeComponent

public partial class ChatMenuPage : ContentPage
{
    public ChatMenuPage()
    {
        InitializeComponent();
    }
}
bq8i3lrv

bq8i3lrv3#

您必须更改.xaml文件中的名称空间声明。
另外,在Appshell.xaml中更改:

*xmlns:{XML namespace name}="clr-namespace:{.NET namespace}"*

教程Create a .NET MAUI app中的这个链接可能也有帮助:

相关问题