WPF WrapPanel/StackPanel与DataTemplate一起使用?

7

如何在WrapPanel或StackPanel中使用DataTemplate?

在ListBox中很容易,但我找不到在面板上实现的方法...

编辑:我想要一个像WrapPanel一样排列项的ListBox。

2个回答

15

如果我理解你的意思正确,你可以使用容器的ItemsPanel属性。类似地,我使用了这样的方法来使用水平StackPanel布局我的ItemsControl:

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

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

<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapPanel />
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>

-1

这些面板没有DataTemplate属性。

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

希望对您有所帮助


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接