Reputation: 25631
I want the ability to bind a collection of LocationCollection instances to Bing Maps control in WP7 (Silverlight). I'm able to bind a single instance of a polygon using the following XAML:
<Microsoft_Phone_Controls_Maps:MapLayer.Children>
<Microsoft_Phone_Controls_Maps:MapPolygon Locations="{Binding Polygon}"
Fill="{StaticResource PolygonFillBrush}"
Stroke="{StaticResource PolygonStrokeBrush}"
StrokeThickness="4"
Opacity="1">
</Microsoft_Phone_Controls_Maps:MapPolygon>
</Microsoft_Phone_Controls_Maps:MapLayer.Children>
This has bound a single LocationCollection using the Polygon property on the ViewModel. I want to be able to bind an ObservableCollection to the MapLayer so I can draw as many polygons as is required.
I can do this in code (code-behind) but I would prefer to declare this in XAML, is this possible?
Upvotes: 2
Views: 1861
Reputation: 26344
Simply use a MapItemsControl
(In this example, xmlns:maps = Microsoft_Phone_Controls_Maps)
<maps:MapItemsControl ItemsSource="{Binding Polygons}">
<maps:MapItemsControl.ItemTemplate>
<DataTemplate>
<maps:MapPolygon Locations="{Binding Polygon}"
Fill="{StaticResource PolygonFillBrush}"
Stroke="{StaticResource PolygonStrokeBrush}"
StrokeThickness="4"
Opacity="1" />
</DataTemplate>
</maps:MapItemsControl.ItemTemplate>
</maps:MapItemsControl>
Upvotes: 2