在 XAML 中绑定 MapIcon

Row*_*haw 5 xaml bing-maps uwp uwp-maps

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

在我的 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">
    <Maps:MapIcon Location="{Binding Geopoint}" Title="{Binding AttractionName}" />
</Maps:MapControl>
Run Code Online (Sandbox Code Playgroud)

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

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

Row*_*haw 2

我最终通过 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>
Run Code Online (Sandbox Code Playgroud)

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

虽然这没有使用 MapIcon,但它提供了我们的应用程序如何在 Windows Phone 7.x/8.x 中显示位置的外观和感觉,因此可能对其他想要类似的人有所帮助。