如何在WPF中集成GMap.NET?如何在WPF中使用GMap.NET Winforms控件? [英] How to integrate GMap.NET in WPF? How to work with GMap.NET winforms controls in WPF?

查看:239
本文介绍了如何在WPF中集成GMap.NET?如何在WPF中使用GMap.NET Winforms控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白如何在WPF中集成GMap.NET.我正在尝试使用XAML进行操作,并且没有任何想法.我正在尝试类似的方法: https://msdn.microsoft.com/zh-CN/library/ms742875(v=vs.110).aspx .但这对我不起作用.那么,该怎么做呢?

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应用程序,想在WPF窗口中使用GMap.NET lib winforms控件.有点像,但是在WPF中:

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

此外,通常,如何在WPF中使用WinForms控件参数?例如,如何更改地图提供者?在Winforms中,它非常简单,但是如何在WPF中实现呢?我被卡住了,所以.更改mapprovider的示例:

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:

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

或者,也许我只是走错了路?我对WPF完全陌生.

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

推荐答案

  1. 将GMap NET参考添加到您的项目中,以使参考列表中包含"GMap.NET.Core"和"GMap.NET.WindowsPresentation"
  2. 在您的XAML文件中,使用其他命名空间(xmlns)声明,添加

  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"

  • 将GMap NET对象添加到您要运行的XAML正文中,例如

  • Add the GMap NET object in to the XAML body where you want it to go, e.g.

    
    
        <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;
        }
    
    

    这篇关于如何在WPF中集成GMap.NET?如何在WPF中使用GMap.NET Winforms控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆