简体   繁体   中英

Windows Phone 8.1 WinRT set Button location on MapControl

I want to set the Button on MapControl in my WP 8.1 app. The problem is the Button isn't on location of the element only is on top-left of the Map and it is moving. Location in binding is Geopoint. Here's my code:

<Maps:MapControl x:Name="MapEvent" Grid.Row="1">

        <Maps:MapItemsControl ItemsSource="{Binding}">
            <Maps:MapItemsControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <Button Maps:MapControl.Location="{Binding Location}" 
                                Maps:MapControl.NormalizedAnchorPoint="0.5,0.5" 
    Content="{Binding Name}"/>
                    </StackPanel>
                </DataTemplate>
            </Maps:MapItemsControl.ItemTemplate>
        </Maps:MapItemsControl>

    </Maps:MapControl>

Here is an excerpt of some code working for me :

public class PhotoInfo
{
    public String Label { get; set; }
    public String FileName { get; set; }
    public Geocoordinate Coordinate { get; set; }
    public Point NormalizedAnchorPoint { get { return new Point(0.5, 1); } }
}

I just reminded that one should not bind on Windows.Devices.Geolocation.Geocoordinate but on Windows.Devices.Geolocation.Geopoint .

This is why Binding of m:MapControl.Location is on Coordinate.Point

<m:MapControl ZoomLevel="{Binding ZoomLevel}" Center="{Binding Center}"  MapServiceToken="xxx">
    <m:MapItemsControl ItemsSource="{Binding PhotoInfos}">
        <m:MapItemsControl.ItemTemplate>
            <DataTemplate>
                <Image m:MapControl.Location="{Binding Coordinate.Point}" 
                                       Source="ms-appx:///Assets/pushpin.png" 
                               m:MapControl.NormalizedAnchorPoint="{Binding NormalizedAnchorPoint}" Width="20" Height="45" Tapped="Image_Tapped"/> 
            </DataTemplate>
        </m:MapItemsControl.ItemTemplate>
    </m:MapItemsControl>
</m:MapControl>

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.

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