windows phone 8.1中地图上的绑定位置

本文关键字:绑定 位置 地图 phone windows | 更新日期: 2023-09-27 18:26:46

我正在尝试将图像绑定到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;

windows phone 8.1中地图上的绑定位置

绑定错误。

根据XAML,类应该具有这两个属性,一个是picture以显示图像,另一个是location以设置图像在地图上的位置。我将它们重命名为MapPictureMapLocation,以遵循CamelCase命名约定。

类别:

class MapIcon
{
    public ImageSource MapPicture { get; set;}
    public Location MapLocation { get; set; }
} 

更新后的XAML只是重命名了两个属性:

<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;
}