7

我必须怎么做才能在 WrapPanel 或 StackPanel 中使用 DataTemplate?

在 ListBox 上它很容易,但我找不到在面板上做它的方法......

编辑:我想要的是一个列表框,它可以像 WrapPanel 一样放置项目。

4

2 回答 2

15

如果我理解正确,您可以使用容器的 ItemsPanel 属性。我使用了类似的东西来使用水平 StackPanel 制作我的 ItemsControl 布局:

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal" />
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>

因此,更具体地说,对于您的情况:

<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapPanel />
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>
于 2009-03-20T15:35:02.570 回答
-1

这些面板没有 DataTemplate 属性..

但是,您可以为这些面板使用 ControlTemplate,并在这些面板的 Template 属性中设置它们...

高温高压

于 2009-03-20T15:34:00.683 回答