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

人盡茶涼 提交于 2019-12-08 09:43:46

问题


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?

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

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;

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


回答1:


  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.


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

  1. In the mapView_Loaded function of the code , set up the map object

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



来源:https://stackoverflow.com/questions/42973526/how-to-integrate-gmap-net-in-wpf-how-to-work-with-gmap-net-winforms-controls-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!