Skip to main content

How to: Bind a Map Control to a Datasource

This example illustrates how to bind a map control to data, which is stored in an external XML file. The XML data source contains information about wrecked ships including ship coordinates.

In this example, the map control automatically generates ship images based on data from a datasource, along with a description for each image on a tooltip.

To accomplish this task, create a required data source (in this example, this is a collection of business objects generated by the LoadDataFromXML method) or use the existing ones. Then, assign a data source to the VectorLayer.ItemsSource property. In addition, specify latitude and longitude data members (VectorLayer.LatitudeDataMember and VectorLayer.LongitudeDataMember) to define map coordinates for generated vector elements.

To specify the appearance of these elements, define a data template using the VectorLayer.ItemTemplate property. You can also define a template for tooltips using the VectorLayerBase.ToolTipContentTemplate property.

Note that if you run this sample as is, you will get a warning message saying that the specified Bing Maps key is invalid. To learn more about Bing Map keys, please refer to the How to: Get a Bing Maps Key tutorial.