Peter
Peter

Reputation: 38455

WPF WrapPanel/StackPanel with DataTemplate?

What must I do to use a DataTemplate in a WrapPanel or StackPanel?

On a ListBox its so easy but i cant find a way to do it on a Panel...

Edit: What i want is a ListBox that places the items like a WrapPanel.

Upvotes: 7

Views: 11313

Answers (2)

Rich
Rich

Reputation: 36806

If I understand you correctly, you can use the ItemsPanel property of your container. I used something similar to make my ItemsControl layout using a horizontal StackPanel:

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

So, more specifically for your case:

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

Upvotes: 15

Arcturus
Arcturus

Reputation: 27055

There isn't a DataTemplate property for those panels..

You can however use a ControlTemplate for these panels, and set these in the Template property of these panels...

HTH

Upvotes: -1

Related Questions