簡體   English   中英

Windows Phone 8.1中地圖上的綁定位置

[英]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設置在地圖上的圖像位置。 我將它們重命名為MapPictureMapLocation以遵循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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM