在XAML中绑定MapIcon [英] Binding a MapIcon in XAML

查看:106
本文介绍了在XAML中绑定MapIcon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用MapControl,显示当前查看位置的MapIcon.

I'm trying to use a MapControl, showing a MapIcon for the currently viewed location.

在我的XAML中,我得到了:

In my XAML, I've got:

<Maps:MapControl x:Name="MapControl" ZoomLevel="14" Center="{Binding Geopoint, Mode=OneWay}" Margin="-12,0,-12,0" Tapped="directions_Click" Height="200" MapServiceToken="{StaticResource BingMapsKey}" PanInteractionMode="Disabled" RotateInteractionMode="Disabled">
    <Maps:MapIcon Location="{Binding Geopoint}" Title="{Binding AttractionName}" />
</Maps:MapControl>

我要绑定的项目正在页面的其他位置使用(例如,地图位于正确的位置中心),但是MapIcon没有显示,也没有给出任何提示?

The items that I'm binding to are being used elsewhere on the page (e.g. the map centres on the correct location), but the MapIcon does not show, nor give any hint as to why?

据我所见,来自MSDN的 我应该能够以这种方式进行绑定(尽管专门针对<MapIcon>的示例是动态添加它们的,但确实显示了直接在XAML中绑定的其他XAML对象).我在这里标记XAML错误吗?

As far as I can see from MSDN I should be able to bind in this manner (although the example specifically for <MapIcon>s is adding them dynamically, it does show other XAML objects being bound directly in the XAML). Am I marking up the XAML wrong here?

推荐答案

我最终通过XAML构建了自己的图钉:

I've ended up building my own pushpin, via XAML:

 <Maps:MapControl x:Name="MapControl" ZoomLevel="14" Center="{Binding Geopoint, Mode=OneWay}" Margin="-12,0,-12,0" Tapped="directions_Click" Height="200" MapServiceToken="{StaticResource BingMapsKey}" PanInteractionMode="Disabled" RotateInteractionMode="Disabled">
     <Grid HorizontalAlignment="Left" Maps:MapControl.Location="{Binding Geopoint}" Maps:MapControl.NormalizedAnchorPoint="0,1">
         <Grid.RowDefinitions>
             <RowDefinition Height="*" />
             <RowDefinition Height="*" />
         </Grid.RowDefinitions>

         <Border Background="{ThemeResource SystemControlBackgroundAccentBrush}" Grid.Row="0">
             <TextBlock Text="{Binding AttractionName}" HorizontalAlignment="Left" />
         </Border>
         <Polygon Points="0,0 12.5,0 0,20" Fill="{ThemeResource SystemControlBackgroundAccentBrush}" StrokeThickness="0" Grid.Row="1" />
     </Grid>
 </Maps:MapControl>

这允许绑定位置(通过Maps:MapControl.Location="{Binding Geopoint}"),并且可以设置相对位置,以便将点保持在正确的位置(通过Maps:MapControl.NormalizedAnchorPoint="0,1"-即图钉内容的左下角)

This allows the position to be bound (via Maps:MapControl.Location="{Binding Geopoint}") and the relative position can be set so the point remains at the correct location (via Maps:MapControl.NormalizedAnchorPoint="0,1" - i.e. bottom left of the pin content)

虽然这没有使用MapIcon,但是这使我们的应用程序在Windows Phone 7.x/8.x中显示位置的方式有了感觉,因此可能对其他想要类似功能的人有所帮助.

Whilst this isn't using a MapIcon, This gives a look and feel to how our app showed locations with Windows Phone 7.x/8.x so may be helpful for others wanting similar.

这篇关于在XAML中绑定MapIcon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆