有没有办法避免
以下是XAML:
ItemsControl
在我的项中包装ContentPresenter
的生成?我的ItemsControl
绑定了一个VM属性,我正在使用一个DataTemplate
在我的ItemControl资源中(没有x:Key
)来自定义我的集合对象的外观。这一切都很好,但是通过Snoop检查发现,所有我的集合对象都被包裹在ContentPresenter
内而不是直接添加到面板中。这个事实给我带来了一些其他问题。有没有办法避免额外的包装?以下是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>
ItemsControl
的类,并重写 GetContainerForItemOverride 方法,以便直接返回一个Ellipse
控件。 - ClemensDataTemplate
管理)吗? - dotNET