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

.NET 8.0 MAUI在Windows用Map控件报错Handler not found 求助

解决Windows平台MAUI Map控件“Handler not found”错误

必要配置步骤

  • 确认NuGet包安装:确保项目已安装Microsoft.Maui.Controls.Maps和Microsoft.Maui.Maps NuGet包(.NET 8中部分场景默认包含,但建议手动确认并更新至最新稳定版)。
  • 注册Windows平台地图处理程序:在MauiProgram.cs中针对Windows平台添加地图处理程序注册,修改CreateMauiApp方法:
public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .ConfigureFonts(fonts =>
        {
            fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
            fonts.AddFont("OpenSans-Semibold.ttf", "OpenSansSemibold");
        })
        .UseMauiMaps();

    // 针对Windows平台注册地图处理程序
#if WINDOWS
    builder.ConfigureMauiHandlers(handlers =>
    {
        handlers.AddHandler<Microsoft.Maui.Controls.Maps.Map, Microsoft.Maui.Maps.Handlers.MapHandler>();
    });
#endif

    return builder.Build();
}
  • 修复XAML语法错误:你的视图代码存在标签不匹配问题,ScrollView的子元素需为单个容器,修正后的XAML如下:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:mapas="clr-namespace:Microsoft.Maui.Controls.Maps;assembly=Microsoft.Maui.Controls.Maps"
             x:Class="Test.MainPage"
             BackgroundColor="Gray">
   
    <ScrollView>
        <VerticalStackLayout>
            <mapas:Map x:Name="mapa" Margin="10,10,10,10"/>
        </VerticalStackLayout>
    </ScrollView>
</ContentPage>
  • 配置Windows地图权限:在Windows项目的Package.appxmanifest中添加地图权限:
    1. 打开Package.appxmanifest,切换到“功能”选项卡。
    2. 勾选“地图”权限后保存文件。

说明

.NET 8的MAUI Map控件完全支持Windows平台,完成上述配置即可解决“Handler not found”错误,确保地图控件正常初始化和渲染。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.02 19:45:06