I'm trying to bind images on locations on map in windows phone 8.1:
<Maps:MapControl x:Name="RestoMap" MapServiceToken="" Height="520" Margin="0,50,0,0" Width="380" ZoomLevel="8">
<Maps:MapItemsControl x:Name="MapIcons" >
<Maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Background="DarkSlateBlue" Width="170" Height="170">
<Image Margin="0,0,0,0" HorizontalAlignment="Center" Source="{Binding picture}" Width="150" Height="100" Maps:MapControl.Location="{Binding location}"/>
</StackPanel>
</DataTemplate>
</Maps:MapItemsControl.ItemTemplate>
</Maps:MapItemsControl>
</Maps:MapControl>
Code: the image didn't appear on map any help
{
double latitude = ....;
double longitude = ....;
Location location = new Location();
location.Latitude = latitude;
location.Longitude = longitude;
locations.Add(location);
}
MapIcons.ItemsSource = this.locations;
The binding is wrong.
According to your XAML, the class should have these two properties , one is picture
to show the image, and the other is location
to set the image location on the map. I rename them as MapPicture
and MapLocation
to follow the CamelCase naming convention.
The class:
class MapIcon
{
public ImageSource MapPicture { get; set;}
public Location MapLocation { get; set; }
}
and the updated XAML-just rename the 2 properties:
<DataTemplate>
<StackPanel Background="DarkSlateBlue" Width="170" Height="170">
<Image Margin="0,0,0,0" HorizontalAlignment="Center" Source="{Binding MapPicture}" Width="150" Height="100" Maps:MapControl.Location="{Binding MapLocation}"/>
</StackPanel>
</DataTemplate>
And how you bind a collection of MapIcon's to the MapItemsControl
.
ObservableCollection<MapIcon> icons = new ObservableCollection<MapIcon>();
private void ShowMapIcons()
{
BitmapImage img = new BitmapImage(....);
double latitude = ....;
double longitude = ....;
Location location = new Location();
location.Latitude = latitude;
location.Longitude = longitude;
MapIcon icon = new MapIcon() { MapLocation = location, ImageSource = img };
icons.Add(icon);
MapIcons.ItemsSource = icons;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.