如何在WPF中集成GMap.NET?如何在 WPF 中使用 GMap.NET winforms 控件?

How to integrate GMap.NET in WPF? How to work with GMap.NET winforms controls in WPF?

我不明白如何在 WPF 中集成 GMap.NET。我正在尝试使用 XAML 来做到这一点,但没有任何想法。我正在尝试这样的事情:https://msdn.microsoft.com/en-us/library/ms742875(v=vs.110).aspx。但这对我不起作用。那么,怎么做呢?

我有 WPF 应用程序,想在 WPF window 中使用 GMap.NET lib winforms 控件。像那样,但在 WPF 中:

另外,一般来说,如何在 WPF 中使用 WinForms 控件参数?例如,如何更改 Map Provider?在 winforms 中它很简单,但是在 WPF 中如何做呢?我卡住了,所以。更改地图提供者的示例:

gmap.MapProvider = GMap.NET.MapProviders.ArcGIS_World_Street_MapProvider.Instance;

或者,也许,我只是走错了路?我是 WPF 的新手。

  1. 将 GMap NET 引用添加到您的项目,这样您的引用列表中就有 "GMap.NET.Core" 和 "GMap.NET.WindowsPresentation"
  2. 在您的 XAML 文件中,使用其他命名空间 (xmlns) 声明,添加

    xmlns:gmaps="clr-namespace:GMap.NET.WindowsPresentation;assembly=GMap.NET.WindowsPresentation"
    
  3. 将 GMap NET 对象添加到 XAML 正文中您希望它去的地方,例如


    <Grid>
    <gmaps:GMapControl x:Name="mapView" Loaded="mapView_Loaded" />
    </Grid>

  1. 在代码的mapView_Loaded函数中,设置地图对象

        private void mapView_Loaded(object sender, RoutedEventArgs e)
        {
            GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerAndCache;
            // choose your provider here
            mapView.MapProvider = GMap.NET.MapProviders.OpenStreetMapProvider.Instance;
            mapView.MinZoom = 2;
            mapView.MaxZoom = 17;
            // whole world zoom
            mapView.Zoom = 2;
            // lets the map use the mousewheel to zoom
            mapView.MouseWheelZoomType = GMap.NET.MouseWheelZoomType.MousePositionAndCenter;
            // lets the user drag the map
            mapView.CanDragMap = true;
            // lets the user drag the map with the left mouse button
            mapView.DragButton = MouseButton.Left;
    }