メインアイテムのItemTemplate
を作ってみましょう別のアイテムコントロールを別のキャンバスにItemsPanel
としますか? (私は最初のレイヤーだけを表示すべき理由は見当たりません)
実際、主なItemsControlはCanvasである必要はありません。グリッドも同様ですZオーダー、グリッドを使用する場合、レイヤーの順序はコレクションの外観と同じです)。
例(ビット冗長それについて何もすることはできません):H.B同様
<ItemsControl ItemsSource="{Binding Data}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Grid />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding LayerItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style TargetType="{x:Type ContentPresenter}">
<!-- Here would the binding to some properties that take care of placement -->
<Setter Property="Canvas.Top" Value="{Binding Top}" />
<Setter Property="Canvas.Left" Value="{Binding Left}" />
</Style>
</ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate>
<!-- Some template for the individual items -->
<DataTemplate>
<Border Padding="5" BorderThickness="1" BorderBrush="Red" CornerRadius="3"
Background="White">
<TextBlock Text="{Binding Name}" />
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
ありがとうございます!これは私が実装しようとしていた初期の解決策でしたが、私は間違ったことをしていたと思います。今はうまくいきます、もう一度感謝します。 – ssaammuueell
あなたが大歓迎です、それは喜んで助けた:) –