Virtual Earth and WPF (Code Samples)

This content is available in the Windows Developer docs at MapControl for Windows Forms and WPF - Windows Community Toolkit | Microsoft Learn

MapControl for Windows Forms and WPF

 

The MapControl class enables you to display a symbolic or photorealistic map in your Windows Forms or WPF desktop application. This is one of several wrapped Universal Windows Platform controls that are available for Windows Forms and WPF applications as part of a feature called XAML Islands. For more information, see UWP controls in desktop applications (XAML Islands).

This control shows rich and customizable map data including road maps, aerial, 3D, views, directions, search results, and traffic. You can also display the user's location, directions, and points of interest.

MapControl example

 Note

If you have feedback about this control, create a new issue in the microsoft-ui-xaml repo and leave your comments there.

About MapControl

This control wraps an instance of the UWP Windows.UI.Xaml.Controls.Maps.MapControl class. The WPF version of this control is located in the Microsoft.Toolkit.Wpf.UI.Controls namespace. The Windows Forms version is located in the Microsoft.Toolkit.Forms.UI.Controls namespace. You can find additional related types (such as enums and event args classes) in the Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT namespace.

Prerequisites

Before you can use this control, you must follow these instructions to configure your project to support XAML Islands.

Known issues and limitations

See our list of known issues for WPF and Windows Forms controls in the Windows Community Toolkit repo.

Syntax


XAML
<Window x:Class="TestSample.MainWindow" ...
  xmlns:controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls"
...>


<controls:MapControl x:Name="mapControl" DockPanel.Dock="Top" ZoomInteractionMode="GestureAndControl"
    TiltInteractionMode="GestureAndControl" MapServiceToken="EnterYourAuthenticationKeyHere" />

Code example


C#
private async void MapControl_Loaded(object sender, RoutedEventArgs e)
{
    // Specify a known location.
    BasicGeoposition cityPosition = new BasicGeoposition() { Latitude = 47.604, Longitude = -122.329 };
    var cityCenter = new Geopoint(cityPosition);

    // Set the map location.
    await (sender as MapControl).TrySetViewAsync(cityCenter, 12);
}

Properties

The following properties wrap corresponding properties of the wrapped UWP Windows.UI.Xaml.Controls.Maps.MapControl object. See the links in this table for more information about each property.

Property Type Description
ActualCamera MapCamera Wraps the ActualCamera property.
BusinessLandmarksEnabled bool Wraps the BusinessLandmarksEnabled property.
BusinessLandmarksVisible bool Wraps the BusinessLandmarksVisible property.
Center Geopoint Wraps the Center property.
CustomExperience MapCustomExperience Wraps the CustomExperience property.
DesiredPitch double Wraps the DesiredPitch property.
Heading double Wraps the Heading property.
Is3DSupported bool Wraps the Is3DSupported property.
IsStreetsideSupported bool Wraps the IsStreetsideSupported property.
LandmarksVisible bool Wraps the LandmarksVisible property.
Layers IList<MapLayer> Wraps the Layers property.
LoadingStatus MapLoadingStatus Wraps the LoadingStatus property.
MapColorScheme ColorScheme Wraps the MapColorScheme property.
MapElements IList<MapElement> Wraps the MapElements property.
MapProjection MapProjection Wraps the MapProjection property.
MapServiceToken string Wraps the MapServiceToken property.
MaxZoomLevel double Wraps the MaxZoomLevel property.
MinZoomLevel double Wraps the MinZoomLevel property.
PanInteractionMode MapPanInteractionMode Wraps the PanInteractionMode property.
PedestrianFeaturesVisible bool Wraps the PedestrianFeaturesVisible property.
Pitch double Wraps the Pitch property.
Region string Wraps the Region property.
RotateInteractionMode MapInteractionMode Wraps the RotateInteractionMode property.
Routes IList<MapRouteView> Wraps the Routes property.
Scene MapScene Wraps the Scene property.
Style MapStyle Wraps the Style property.
StyleSheet MapStyleSheet Wraps the StyleSheet property.
TargetCamera MapCamera Wraps the TargetCamera property.
TileSources IList<MapTileSource> Wraps the TileSources property.
TiltInteractionMode MapInteractionMode Wraps the TiltInteractionMode property.
TrafficFlowVisible bool Wraps the TrafficFlowVisible property.
TransitFeaturesEnabled bool Wraps the TransitFeaturesEnabled property.
TransitFeaturesVisible bool Wraps the TransitFeaturesVisible property.
TransformOrigin Point Wraps the TransformOrigin property.
WatermarkMode MapWatermarkMode Wraps the WatermarkMode property.
ZoomInteractionMode MapInteractionMode Wraps the ZoomInteractionMode property.
ZoomLevel double Wraps the ZoomLevel property.

Methods

The following methods wrap corresponding methods of the wrapped UWP Windows.UI.Xaml.Controls.Maps.MapControl object. See the links in this table for more information about each method.

Method Return Type Description
FindMapElementsAtOffset(Point) IReadOnlyList<MapElement> Wraps the FindMapElementsAtOffset(Point) method.
FindMapElementsAtOffset(Point, double) IReadOnlyList<MapElement> Wraps the FindMapElementsAtOffset(Point, double) method.
GetLocationFromOffset(Point, Geopoint) void Wraps the GetLocationFromOffset(Point, Geopoint) method.
GetLocationFromOffset(Point, AltitudeReferenceSystem, Geopoint) void Wraps the GetLocationFromOffset(Point, AltitudeReferenceSystem, Geopoint) method.
GetOffsetFromLocation void Wraps the GetOffsetFromLocation method.
GetVisibleRegion Geopath Wraps the GetVisibleRegion method.
IsLocationInView void Wraps the IsLocationInView method.
StartContinuousPan void Wraps the StartContinuousPan method.
StartContinuousRotate void Wraps the StartContinuousRotate method.
StartContinuousTilt void Wraps the StartContinuousTilt method.
StartContinuousZoom void Wraps the StartContinuousZoom method.
StopContinuousPan void Wraps the StopContinuousPan method.
StopContinuousRotate void Wraps the StopContinuousRotate method.
StopContinuousTilt void Wraps the StopContinuousTilt method.
StopContinuousZoom void Wraps the StopContinuousZoom method.
TryGetLocationFromOffset(Point, Geopoint) bool Wraps the TryGetLocationFromOffset(Point, Geopoint) method.
TryGetLocationFromOffset(Point, AltitudeReferenceSystem, Geopoint) bool Wraps the TryGetLocationFromOffset(Point, AltitudeReferenceSystem, Geopoint) method.
TryPanAsync bool Wraps the TryPanAsync method.
TryPanToAsync bool Wraps the TryPanToAsync method.
TryRotateAsync bool Wraps the TryRotateAsync method.
TryRotateToAsync bool Wraps the TryRotateToAsync method.
TrySetSceneAsync(MapScene) bool Wraps the TrySetSceneAsync(MapScene) method.
TrySetSceneAsync(MapScene, MapAnimationKind) bool Wraps the TrySetSceneAsync(MapScene, MapAnimationKind) method.
TrySetViewAsync(Geopoint) bool Wraps the TrySetViewAsync(Geopoint) method.
TrySetViewAsync(Geopoint, Nullable<double>) bool Wraps the TrySetViewAsync(Geopoint, Nullable<double>) method.
TrySetViewAsync(Geopoint, Nullable<double>, Nullable<double>, Nullable<double>) bool Wraps the TrySetViewAsync(Geopoint, Nullable<double>, Nullable<double>, Nullable<double>) method.
TrySetViewAsync(Geopoint, Nullable<double>, Nullable<double>, Nullable<double>, MapAnimationKind) bool Wraps the TrySetViewAsync(Geopoint, Nullable<double>, Nullable<double>, Nullable<double>, MapAnimationKind) method.
TryTiltAsync bool Wraps the TryTiltAsync method.
TryTiltToAsync bool Wraps the TryTiltToAsync method.
TryZoomInAsync bool Wraps the TryZoomInAsync method.
TryZoomOutAsync bool Wraps the TryZoomOutAsync method.
TryZoomToAsync bool Wraps the TryZoomToAsync method.

Events

The following events wrap corresponding events of the wrapped UWP Windows.UI.Xaml.Controls.Maps.MapControl object. See the links in this table for more information about each event.

Event Description
ActualCameraChanged Wraps the ActualCameraChanged event.
ActualCameraChanging Wraps the ActualCameraChanging event.
CenterChanged Wraps the CenterChanged event.
CustomExperienceChanged Wraps the CustomExperienceChanged event.
HeadingChanged Wraps the HeadingChanged event.
LoadingStatusChanged Wraps the LoadingStatusChanged event.
MapContextRequested Wraps the MapContextRequested event.
MapDoubleTapped Wraps the MapDoubleTapped event
MapElementClick Wraps the MapElementClick event.
MapElementPointerEntered Wraps the MapElementPointerEntered event.
MapElementPointerExited Wraps the MapElementPointerExited event.
MapHolding Wraps the MapHolding event.
MapRightTapped Wraps the MapRightTapped event.
MapTapped Wraps the MapTapped event.
PitchChanged Wraps the PitchChanged event.
TargetCameraChanged Wraps the TargetCameraChanged event.
TransformOriginChanged Wraps the TransformOriginChanged event.
ZoomLevelChanged Wraps the ZoomLevelChanged event.

Requirements

Device family .NET 4.6.2, Windows 10 (introduced v10.0.17709.0)
Namespace Windows Forms: Microsoft.Toolkit.Forms.UI.Controls
WPF: Microsoft.Toolkit.Wpf.UI.Controls
NuGet package Windows Forms: Microsoft.Toolkit.Forms.UI.Controls
WPF: Microsoft.Toolkit.Wpf.UI.Controls

API