Windows Phone 8.1 WinRT set Button location on MapControl

╄→尐↘猪︶ㄣ 提交于 2019-12-12 02:48:10

问题


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>

回答1:


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>


来源:https://stackoverflow.com/questions/33616665/windows-phone-8-1-winrt-set-button-location-on-mapcontrol

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!