You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

迁移Xamarin.Forms至.NET MAUI时遇XamlC错误:无法解析ContentView/ContentPage

解决Xamarin.Forms迁移至.NET MAUI时XFC0000错误的方案

核心修复步骤

  • 修正项目SDK配置
    确保Forms项目的.csproj中添加MAUI必要属性,替换成你实际使用的.NET版本(如net6.0、net8.0):

    <PropertyGroup>
      <TargetFrameworks>net7.0-android;net7.0-ios;net7.0-maccatalyst</TargetFrameworks>
      <UseMaui>true</UseMaui>
      <SingleProject>true</SingleProject>
      <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>
    
  • 确保XAML命名空间完全替换
    所有XAML文件的根节点必须使用MAUI命名空间,移除旧的Xamarin.Forms引用:

    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    
  • 验证XAML生成操作
    确认.csproj中XAML文件的生成操作已设为MauiXaml:

    <MauiXaml Include="YourPage.xaml" />
    
  • 彻底清理重建

    • 删除项目目录下的bin和obj文件夹
    • 执行命令:dotnet clean → dotnet restore → dotnet build
  • 检查MauiProgram.cs配置
    确保应用入口正确注册MAUI框架:

    using Microsoft.Maui;
    using Microsoft.Maui.Hosting;
    
    namespace YourAppNamespace;
    
    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder.UseMauiApp<App>();
            return builder.Build();
        }
    }
    

    同时确认App.cs继承自Microsoft.Maui.Controls.Application。

额外排查点

  • 自定义控件需同步更新命名空间,继承MAUI对应基类(如Microsoft.Maui.Controls.ContentView)
  • 检查.csproj中是否残留Xamarin.Forms相关的<PackageReference>条目

内容的提问来源于stack exchange,提问作者user20694704

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 23:15:35