Is there a way to avoid generation of ContentPresenter
that ItemsControl
wraps my items in? My ItemsControl
is bound to a VM property and I'm using a DataTemplate
in my ItemControl's Resources (without an x:Key
) to customize the look of my collection objects. This all works fine, but inspecting through Snoop shows that all my collection objects are wrapped inside ContentPresenter
s and not directly added to the Panel. This fact is creating some other issues for me. Is there a way to avoid the extra wrapping?
Here's the XAML:
<ItemsControl ItemsSource="{Binding Path=Children}">
<ItemsControl.Resources>
<DataTemplate DataType="{x:Type vm:Ellipse}">
<Ellipse Fill="{Binding Fill}" Stroke="{Binding Stroke}" />
</DataTemplate>
</ItemsControl.Resources>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Focusable="true" Margin="10" FocusVisualStyle="{x:Null}" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle>
<Style>
<Setter Property="Canvas.Left" Value="{Binding XLoc}" />
<Setter Property="Canvas.Top" Value="{Binding YLoc}" />
<Setter Property="Canvas.ZIndex" Value="{Binding ZOrder}" />
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
DataTemplate
)? – Commeasure