2011-10-24 42 views
2

我希望能夠將一組LocationCollection實例綁定到WP7(Silverlight)中的Bing Maps控件。我可以使用下面的XAML綁定一個多邊形的一個實例:如何將多個(n)多邊形綁定到Bing Map控件

<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> 

這勢必對使用視圖模型的多邊形性能單一LocationCollection。我希望能夠將一個ObservableCollection綁定到MapLayer,以便根據需要繪製儘可能多的多邊形。

我可以在代碼(代碼隱藏)中做到這一點,但我更願意在XAML中聲明這是可能的嗎?

回答

2

只需使用一個MapItemsControl(在這個例子中,的xmlns:地圖= 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> 
+0

我這樣做,在我的情況下,'Polygon'屬性的類型Geopath'的'的對象。但是當試圖綁定時,它引發了一個異常,並帶有消息'「參數不正確。\ r \ n」' –

相關問題