Skip to main content

DevExpress v25.1 Update — Your Feedback Matters

Our What's New in v25.1 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Add a Map Control at Runtime

  • 2 minutes to read

This example demonstrates how to add a MapControl to a WPF application and connect the map to the AzureMapDataProvider at runtime.

  1. Run Microsoft Visual Studio.

  2. Create a new WPF Application project or open an existing one.

  3. Open the Solution Explorer, right-click References and choose Add Reference….

    Add references to the following assemblies in the Extensions tab:

    • DevExpress.Xpf.Map.v25.1
    • DevExpress.Map.v25.1.Core
    • DevExpress.Data.v25.1

    how-to-add-map-control-xaml-2

    Click OK.

  4. Handle the Window’s Loaded event as follows:

    using System.Windows;
    using DevExpress.Xpf.Map;
    
    
    namespace DXMap_Runtime {
        public partial class MainWindow : Window {
            public MainWindow() {
                InitializeComponent();
            }
    
            private void Window_Loaded(object sender, RoutedEventArgs e) {
                // Create a map control and add it to the window.
                MapControl map = new MapControl();
                this.Content = map;
    
                // Create a layer.
                ImageLayer layer = new ImageLayer() {
                    DataProvider = new AzureMapDataProvider() {
                        AzureKey = "Insert your Azure Maps key here.",
                        Tileset = AzureTileset.BaseRoad
                    }
                };
                map.Layers.Add(layer);
                map.ZoomLevel = 4;
                map.CenterPoint = new GeoPoint(40, -100);
            }
        }
    }
    
  5. Run the project to see the result.

See Also