[英]binding location on map in windows phone 8.1
我正在尝试在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>
代码:图像未在地图上显示任何帮助
{
double latitude = ....;
double longitude = ....;
Location location = new Location();
location.Latitude = latitude;
location.Longitude = longitude;
locations.Add(location);
}
MapIcons.ItemsSource = this.locations;
绑定错误。
根据您的XAML,类应该具有这两个属性 ,一个是picture
显示的图像,另一个是location
设置在地图上的图像位置。 我将它们重命名为MapPicture
和MapLocation
以遵循CamelCase命名约定。
班级:
class MapIcon
{
public ImageSource MapPicture { get; set;}
public Location MapLocation { get; set; }
}
并且更新后的XAML-只需重命名2个属性即可:
<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>
以及如何将MapIcon的集合绑定到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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.