问题
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:
- add the GMap NET reference to your project so you have "GMap.NET.Core" and "GMap.NET.WindowsPresentation" in your reference list
In your XAML file, with the other namespace (xmlns) declarations, add,
xmlns:gmaps="clr-namespace:GMap.NET.WindowsPresentation;assembly=GMap.NET.WindowsPresentation"
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>
- 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