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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42973526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 14:03:10  来源:igfitidea点击:

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

c#wpfwinformsgmap.net

提问by Golovach Grach

I can not understand how to integrate GMap.NET in WPF. I am trying to do it using XAML and have no ideas. I am trying smth like that: https://msdn.microsoft.com/en-us/library/ms742875(v=vs.110).aspx. But it doesn't work for me. So, how to do it?

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

I have WPF application and want to use GMap.NET lib winforms controls inside WPF window. Smth like that but in WPF:

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

enter image description here

在此处输入图片说明

Also, in general, how to work with WinForms controls parameters in WPF? How to change Map Provider, for example? In winforms its quite simple, but how to do it in WPF? I got stucked, so. Sample for changing mapprovider:

另外,一般来说,如何在 WPF 中使用 WinForms 控件参数?例如,如何更改 Map Provider?在 winforms 中它很简单,但是如何在 WPF 中做到这一点?我被卡住了,所以。更改 mapprovider 的示例:

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

Or, maybe, I am just on the wrong way? I am completely new in WPF.

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

回答by pm101

  1. add the GMap NET reference to your project so you have "GMap.NET.Core" and "GMap.NET.WindowsPresentation" in your reference list
  2. In your XAML file, with the other namespace (xmlns) declarations, add,

    xmlns:gmaps="clr-namespace:GMap.NET.WindowsPresentation;assembly=GMap.NET.WindowsPresentation"
  3. Add the GMap NET object in to the XAML body where you want it to go, e.g.

  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. In the mapView_Loaded function of the code , set up the map object
  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;
    }