C# 在wpf映射控件上绘制多个图层

C# 在wpf映射控件上绘制多个图层,c#,.net,wpf,google-maps,gis,C#,.net,Wpf,Google Maps,Gis,我有一个带有wpf地图控件和画布的网格,用于在地图上绘制标记 <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <UserControl Grid.Row="0" Content="{Binding CurrentMap}" />

我有一个带有wpf地图控件和画布的网格,用于在地图上绘制标记

    <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <UserControl Grid.Row="0" Content="{Binding CurrentMap}" />
    <UserControl Grid.Row="0" Content="{Binding DrawningCanvas}" />
</Grid>

现在我需要在地图上使用多个图层


我应该使用什么wpf控件绑定到DataContext中的
ObservableCollection
,并将它们相互绘制?

您似乎有些困惑。
可观测集合
是数据项的集合。
Canvas
是一个UI控件。因此,您永远不应该在中有UI元素的数据项集合

相反,您可以有一个
Marker
数据类,其中包含标记位置的
X
Y
属性,还可以使用
Name
ImageSource
属性来定义它在UI中的外观。然后,您可以拥有一个名为
Markers
ObservableCollection
,类型为
Marker
,可以绑定到
ItemsControl
ItemsSource
属性。最后,您可以将
Canvas
设置为
ItemsControl
ItemsPanel

<ItemsControl ItemsSource="{Binding Markers}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <Canvas />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemContainerStyle>
        <Style TargetType="ContentPresenter">
            <Setter Property="Canvas.Left" Value="{Binding X}"/>
            <Setter Property="Canvas.Top" Value="{Binding Y}"/>
        </Style>
    </ItemsControl.ItemContainerStyle>
    <ItemsControl.ItemTemplate>
        <DataTemplate DataType="{x:Type YourXmlNamespacePrefix:Marker}">
            <StackPanel Orientation="Horizontal">
                <Image Source="{Binding ImageSource}" />
                <TextBlock Text="{Binding Name}" />
            </StackPanel>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>


我真的不知道你为什么想要有多个层,因为你可以在同一层上覆盖多个项目,但是如果你真的需要多个层,那么你可以添加更多上面显示的
ItemsControl
元素。

非常感谢,我想这个解决方案解决了我的问题。