Windows Phone 8.1 WinRT在MapControl上设置按钮位置
本文关键字:设置 按钮 位置 MapControl Phone WinRT Windows | 更新日期: 2023-09-27 18:21:11
我想在我的WP 8.1应用程序中设置MapControl上的按钮。问题是按钮不在元素的位置上,只在地图的左上角,它正在移动。绑定中的位置为Geopoint。这是我的代码:
<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>
下面是一些对我有用的代码的摘录:
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); } }
}
我只是提醒大家,不要绑定Windows.Devices.Geolocation.Geocoordinate
,而是绑定Windows.Devices.Geolocation.Geopoint
。
这就是为什么m:MapControl.Location
的结合在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>