Phi*_*hil 13 .net dictionary maui
我正在玩 .Net Maui。我想将地图添加到我的演示应用程序中。不幸的是,地图控件似乎还没有迁移。此外,承诺的控制实施似乎已从 RC 路线图中删除。
还有像这样的现有项目: https: //github.com/amay077/Xamarin.Forms.GoogleMaps 不支持 .Net Maui...
有人已经包含了 .Net Maui 项目的地图并且可以给我一些提示吗?
谢谢!
要在 .NET MAUI 中使用 Google 或 Apple 地图(虽然尚未在 Framework 中),请使用您自己的处理程序。您可以在我们的网站上找到详细的博客文章。
但一般来说,您必须执行以下步骤:
public class MapView : View, IMapView
{ }
Run Code Online (Sandbox Code Playgroud)
这是您在 ContentPage 中使用的控件。
为了渲染视图,MAUI 需要一个独立于平台的入口点。
partial class MapHandler
{
public static IPropertyMapper<MapView, MapHandler> MapMapper = new PropertyMapper<MapView, MapHandler>(ViewMapper)
{ };
public MapHandler() : base(MapMapper)
{ }
}
Run Code Online (Sandbox Code Playgroud)
需要在您的 MauiProgram.cs 中注册
.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(MapHandlerDemo.Maps.Map),typeof(MapHandler));
})
Run Code Online (Sandbox Code Playgroud)
处理程序告诉 MAUI 如何呈现您的控件。因此,您需要为您想要支持的每个平台提供一个处理程序。与 Android 相比,iOS 处理程序的实现更简单、更短。
public partial class MapHandler : ViewHandler<MapView, MKMapView>
{
public MapHandler(IPropertyMapper mapper, CommandMapper commandMapper = null) : base(mapper, commandMapper)
{ }
protected override MKMapView CreatePlatformView()
{
return new MKMapView(CoreGraphics.CGRect.Empty);
}
protected override void ConnectHandler(MKMapView PlatformView)
{ }
protected override void DisconnectHandler(MKMapView PlatformView)
{
// Clean-up the native view to reduce memory leaks and memory usage
if (PlatformView.Delegate != null)
{
PlatformView.Delegate.Dispose();
PlatformView.Delegate = null;
}
PlatformView.RemoveFromSuperview();
}
}
Run Code Online (Sandbox Code Playgroud)
下一步是实现您的 Android 处理程序。
小智 -2
请尝试这样:
<WebView Source="https://embed.windy.com" />
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8645 次 |
| 最近记录: |