网上有很多关于商店应用的WinRT bing地图的教程。这就是我想用WPF做的事情:
我正在将本教程翻译成WPF。然而,在WPF bing地图中,没有MapShapeLayer,例如,这使得无法遵循。
如何使用WPF Bing控件实现此功能?
答案 0 :(得分:0)
好吧,我从未以编程方式向地图添加项目,但我相信您只需将它们添加到地图Children
属性中。我尝试坚持MVVM模式,所以我依靠绑定和底层的viewmodel相应地更新地图。以下是我的一个项目中的XAML示例 - 我认为它会让您朝着正确的方向前进:
<bingControl:Map x:Name="DirectionsMap"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AnimationLevel="Full"
Background="{StaticResource MapBackgroundBrush}"
CredentialsProvider="<YourCredentialsHere>"
ScaleVisibility="Collapsed"
ZoomLevel="5">
<bingControl:Pushpin x:Name="StartPushin"
Width="Auto"
Height="Auto"
Panel.ZIndex="50"
Content="{Binding StartAddress.Name}"
Location="{Binding StartAddress.Location}"
Style="{StaticResource DirectionsEndpointPushpinStyle}" />
<bingControl:Pushpin x:Name="DestinationPushpin"
Width="Auto"
Height="Auto"
Panel.ZIndex="50"
Content="{Binding DestinationAddress.Name}"
Location="{Binding DestinationAddress.Location}"
Style="{StaticResource DirectionsEndpointPushpinStyle}" />
<bingControl:MapItemsControl x:Name="DirectionsEdges"
Panel.ZIndex="10"
ItemsSource="{Binding DirectionsResult.RoutePath}">
<bingControl:MapItemsControl.ItemTemplate>
<DataTemplate>
<bingControl:MapPolyline Panel.ZIndex="20"
Locations="{Binding ''}"
Stroke="#5968F7"
StrokeThickness="4" />
</DataTemplate>
</bingControl:MapItemsControl.ItemTemplate>
</bingControl:MapItemsControl>
</bingControl:Map>