Microsoft.maui.ipropertymapper-类型''不能用作类型参数...没有隐式转换

发布于 2025-02-02 22:01:14 字数 1237 浏览 1 评论 0原文

我正在尝试获取地图上的.NET MAUI并找到了这篇博客文章(链接到官方毛伊岛博客)。 https://www.cayas.de/blog/blog/dotnet-maui-blog/dotnet-maui-maui--定制映射处理程序 我已经在博客结束时下载了链接的回购,但我无法运行它。

在博客文章中,Maphandler代码看起来像这样:

public static IPropertyMapper<IMap, MapHandler> MapMapper = new PropertyMapper<IMap, MapHandler>(ViewMapper)
    {  };

但是在回购中,它看起来像:

public static IPropertyMapper<MapView, MapHandler> MapMapper = new PropertyMapper<MapView, MapHandler>(ViewMapper)
        { };

哪一个对我不起作用,因为我在下面收到错误(在运行时)。

The type 'MapControlDemo.Handlers.MapHandler' cannot be used as type parameter 'TViewHandler' in the generic type or method 'PropertyMapper<TVirtualView, TViewHandler>'. There is no implicit reference conversion from 'MapControlDemo.Handlers.MapHandler' to 'Microsoft.Maui.IElementHandler'

令人困惑的是,还有另一个错误不应该是错误?

有什么想法吗?我联系了作者,他建议这可能是我的毛伊岛版本,因为它对他有用,但我最新。

I'm trying to get maps to work on .net MAUI and found this blog post (linked to from the official MAUI blog). https://www.cayas.de/blog/dotnet-maui-custom-map-handler
I've downloaded the repo linked at the end of the blog but I can't get it to run.

In the blog post the MapHandler code looks like this:

public static IPropertyMapper<IMap, MapHandler> MapMapper = new PropertyMapper<IMap, MapHandler>(ViewMapper)
    {  };

But in the repo it looks like this:

public static IPropertyMapper<MapView, MapHandler> MapMapper = new PropertyMapper<MapView, MapHandler>(ViewMapper)
        { };

Neither of which work for me, as I get the error (at runtime) below.

The type 'MapControlDemo.Handlers.MapHandler' cannot be used as type parameter 'TViewHandler' in the generic type or method 'PropertyMapper<TVirtualView, TViewHandler>'. There is no implicit reference conversion from 'MapControlDemo.Handlers.MapHandler' to 'Microsoft.Maui.IElementHandler'

Confusingly there are another couple of errors that shouldn't be errors??
Other errors

Any ideas? I contacted the author and he suggested it could be my maui version as it works for him, but I'm on the latest.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浮云落日 2025-02-09 22:01:14

也许作者正在Mac上建造。

我已经确认,在Windows上构建的尝试导致构建错误。 VS版本17.3.0预览1.1
但是,我得到的错误是

Error   CS0311  The type 'MapControlDemo.Handlers.MapHandler' cannot be used
 as type parameter 'TViewHandler'
 in the generic type or method 'IPropertyMapper<TVirtualView, TViewHandler>'.
 There is no implicit reference conversion from
 'MapControlDemo.Handlers.MapHandler' to
 'Microsoft.Maui.IElementHandler'.
    MapControlDemo (net6.0-android) C:\...\maui-maps\Handlers\MapHandler.cs 6

,我能够在Android上运行 - 通过选择Android模拟器作为目标(因此使用net6.0 android)并按F5-因此,该错误是误导的。


鉴于这仅在iOS和Android上实现,我建议编辑.csproj以删除Windows平台。我还删除了MacCatalyst(也许可以使用,但我要进行最简单的测试):
更改:

        <TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>

到:

        <TargetFrameworks>net6.0-android;net6.0-ios</TargetFrameworks>

然后我能够建造。

注意:在不添加Google Maps ID的情况下,当在Android上运行时,结果是一个空的地图。

tl; dr 最简单的测试方法是在Mac上,定位iOS。

Perhaps the author was building on a Mac.

I've confirmed that an attempt to build on Windows results in a build error. VS Version 17.3.0 Preview 1.1
The error I got was

Error   CS0311  The type 'MapControlDemo.Handlers.MapHandler' cannot be used
 as type parameter 'TViewHandler'
 in the generic type or method 'IPropertyMapper<TVirtualView, TViewHandler>'.
 There is no implicit reference conversion from
 'MapControlDemo.Handlers.MapHandler' to
 'Microsoft.Maui.IElementHandler'.
    MapControlDemo (net6.0-android) C:\...\maui-maps\Handlers\MapHandler.cs 6

HOWEVER, I was able to RUN on Android - by selected an Android emulator as target (so using net6.0-android) and pressing F5 - therefore that error is misleading.


Given that this is only implemented on iOS and Android, I recommend editing .csproj to REMOVE Windows platform. I also removed MacCatalyst (maybe that would work but I was going for simplest test):
Change:

        <TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
        <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>

To:

        <TargetFrameworks>net6.0-android;net6.0-ios</TargetFrameworks>

Then I was able to build.

NOTE: Without adding a Google Maps ID, when ran on Android, the result was an empty map.

tl;dr Easiest way to test is on a Mac, targetting iOS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文