以下是XAML代码:
<maps:Map x:Name="NearbyMap"
Center="{Binding MapCenter, Mode=TwoWay}"
ZoomLevel="{Binding ZoomLevel, Mode=TwoWay}"
>
<maptk:MapExtensions.Children>
<maptk:MapItemsControl Name="StoresMapItemsControl" ItemsSource="{Binding Treks}">
<maptk:MapItemsControl.ItemTemplate>
<DataTemplate>
<maptk:Pushpin x:Name="RouteDirectionsPushPin" GeoCoordinate="{Binding Location}" Visibility="Visible" Content="test"/>
</DataTemplate>
</maptk:MapItemsControl.ItemTemplate>
</maptk:MapItemsControl>
<maptk:UserLocationMarker x:Name="UserLocationMarker" Visibility="Visible" GeoCoordinate="{Binding MyLocation}"/>
</maptk:MapExtensions.Children>
</maps:Map>
xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
xmlns:maptk="clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit"
PushPinModel 有一个 Location 属性,它是一个 GeoCoordinate。 Treks 是一个 ObservableCollection<PushPinModel>
。 我运行这段代码,只有UserLocationMarker被显示,它是我的当前位置。
ObservableCollection<DependencyObject> children = MapExtensions.GetChildren(NearbyMap); MapItemsControl mapItems = children.FirstOrDefault(x => x.GetType() == typeof(MapItemsControl)) as MapItemsControl; mapItems.ItemsSource = Treks;
- Tobias Helbich