简体   繁体   English

Windows Phone 8.1中地图上的绑定位置

[英]binding location on map in windows phone 8.1

I'm trying to bind images on locations 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>

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. 根据您的XAML,类应该具有这两个属性 ,一个是picture显示的图像,另一个是location设置在地图上的图像位置。 I rename them as MapPicture and MapLocation to follow the CamelCase naming convention. 我将它们重命名为MapPictureMapLocation以遵循CamelCase命名约定。

The class: 班级:

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

and the updated XAML-just rename the 2 properties: 并且更新后的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>

And how you bind a collection of MapIcon's to the MapItemsControl . 以及如何将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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM