WPF WrapPanel/StackPanel与DataTemplate?

Pet*_*ter 5 wpf datatemplate

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

在ListBox上它很容易但我无法在Panel上找到一种方法...

编辑:我想要的是一个ListBox,它将项目放置为WrapPanel.

Ric*_*ich 12

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

<ItemsControl.ItemsPanel>
    <ItemsPanelTemplate>
        <StackPanel Orientation="Horizontal" />
    </ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
Run Code Online (Sandbox Code Playgroud)

所以,更具体地说是针对你的情况:

<ListBox.ItemsPanel>
    <ItemsPanelTemplate>
        <WrapPanel />
    </ItemsPanelTemplate>
</ListBox.ItemsPanel>
Run Code Online (Sandbox Code Playgroud)