Export (0) Print
Expand All

MapItemsControl class

Bing

Represents a control to manage data-binding. This class inherits from ItemsControl.

Constructors

Definition Description

MapItemsControl()

Initializes a new instance of the MapItemsControl class.

Code Examples

Set up the map items control to define a set of locations on the map.

Step1: Define ItemsTemplate and ItemsSource for the MapItemsControl and specify the binding relationship.


<Grid>
  <Grid.Resources>
    <CollectionViewSource x:Name="LocationList"/>
    <DataTemplate x:Key="LogoTemplate">
      <Maps:Pushpin>
        <Maps:MapLayer.Position>
          <Maps:Location Latitude="{Binding Latitude}" Longitude="{Binding Longitude}"></Maps:Location>
        </Maps:MapLayer.Position>
      </Maps:Pushpin>
    </DataTemplate>
  </Grid.Resources>
  <Maps:Map Credentials="INSERT_YOUR_BING_MAPS_KEY">
    <Maps:Map.Children>
      <Maps:MapItemsControl x:Name="ListOfItems"
                            ItemsSource="{Binding Source={StaticResource LocationList}}"
                            ItemTemplate="{StaticResource LogoTemplate}">
      </Maps:MapItemsControl>
    </Maps:Map.Children>
  </Maps:Map>
</Grid>

Step 2: Define the classes that provide the location data.

/// <summary>
/// This class acts as a DataContext for the individual items
/// within MapItemsControl where {Binding Latitude}
/// binds to LocationData.Latitude, {Binding Longitude} binds to
/// LocationData.Longitude, and {Binding Name} binds to LocationData.Name
/// </summary>
public class LocationData
{
    public LocationData()
    {
    }

    public string Name { get; set; }
    public double Latitude { get; set; }
    public double Longitude { get; set; }
}

/// <summary>
/// This class acts as the ItemsSource for the MapItemsControl
/// </summary>
public class LocationDataCollection : List<LocationData>
{
    public LocationDataCollection()
    {
        Add(new LocationData() { Name = "A", Latitude = 47, Longitude = -122 });
        Add(new LocationData() { Name = "B", Latitude = 47, Longitude = -100 });
        Add(new LocationData() { Name = "C", Latitude = 47, Longitude = -80 });
        Add(new LocationData() { Name = "D", Latitude = 47, Longitude = -30 });
        Add(new LocationData() { Name = "E", Latitude = 47, Longitude = 0 });
        Add(new LocationData() { Name = "F", Latitude = 47, Longitude = 50 });
    }
}

Step 3: Assign the data collection to the ItemsSource.

LocationList.Source = new LocationDataCollection();

Show:
© 2014 Microsoft