Skip to main content

How to: Add a Map Control via Code

  • 2 minutes to read

This brief introductory example describes how to add a Map Control to your Silverlight application in code.

  • Run the Microsoft Visual Studio 2010, 2012 or 2013.
  • Create a new Silverlight Application project or open an existing project.
  • Open the Solution Explorer, right-click References and choose Add Reference... to add the Map Control library.

    how-to-add-map-control-xaml-1

  • Then, locate and click the DevExpress.Xpf.Map assembly in the Extensions tab.

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

    Repeat the same actions for the DexExpress.Data and DevExpress.Map.Core assemblies.

    Click OK.

  • Write the following (or similar) code.

    
    using System.Windows;
    using System.Windows.Controls;
    using DevExpress.Xpf.Map;
    
    
    namespace XpfMapApplication {
        public partial class MainPage : UserControl {
            public MainPage() {
                InitializeComponent();
            }
    
            private void UserControl_Loaded(object sender, RoutedEventArgs e) {
                // Create a Map control.
                MapControl map = new MapControl();
                this.Content = map;
    
                // Create a image tile layer with OpenStreetMap data provider.
                ImageTilesLayer tilesLayer = new ImageTilesLayer() {
                    DataProvider = new OpenStreetMapDataProvider()
                };
                map.Layers.Add(tilesLayer);            
            }
        }
    }
    

The MapControl has now been added to your application.

 

TIP

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=E3649.