Reputation: 175
Hello I'am using Bing maps in a WPF app,
My page contains a map.
The dataContext of my page contains a list of Place theses places have a GeoLocation :
public class GeoCoordinate
{
public double latitude { get; set; }
public double longitude { get; set; }
public double altitude { get; set; }
}
public class Place
{
[...]
public GeoCoordinate position { get; set; }
}
public class datacontext
{
[...]
public List<Place> places { get; set; }
}
I would like to bind my list to make pushpins on my map for each place at its coordinate. I tryed to use Map.Children property but without success...
Upvotes: 2
Views: 1951
Reputation: 175
Ok I found it in the xaml I used MapItemsControl property:
<m:Map x:Name="myMap" CredentialsProvider="blabla" ZoomLevel="12" Mode="Road">
<m:MapItemsControl ItemsSource="{Binding places}">
<m:MapItemsControl.ItemTemplate>
<DataTemplate>
<m:Pushpin Location="{Binding position.location}"/>
</DataTemplate>
</m:MapItemsControl.ItemTemplate>
</m:MapItemsControl>
</m:Map>
And I added the location property in GeoCoordinate class :
public class GeoCoordinate
{
public double latitude { get; set; }
public double longitude { get; set; }
public double altitude { get; set; }
public Location location { get { return new Location(latitude, longitude, altitude); } }
}
Upvotes: 3
Reputation: 2952
I would recommend to check the get started section on MSDN so you can get the basics around the use of specific and dedicated classes: http://msdn.microsoft.com/en-us/library/hh830431.aspx
In order to add pushpin elements on your map control, you need to use Pushpin
class, see:
http://msdn.microsoft.com/en-us/library/microsoft.maps.mapcontrol.wpf.pushpin.aspx
And in use it's like this:
// The pushpin to add to the map.
Pushpin pin = new Pushpin();
pin.Location = pinLocation;
// Adds the pushpin to the map.
myMap.Children.Add(pin);
More information regarding how to get started with the pushpin here: http://msdn.microsoft.com/en-us/library/hh709044.aspx
Upvotes: 2