user1178412
user1178412

Reputation: 49

Adding a Wrap Panel to a Listview Item

I have searched all over the internet but to no avail to find the answer to my problem.

I want to be able to have a listview with two columns, one with text and one with a Wrap Panel to drag image into.

I am currently binding the listview to a Dataset, so the columns of said dataset get picked by the WPF column.

<GridViewColumn Width="100" Header="Name" DisplayMemberBinding="{Binding Path=Name}"/>
<GridViewColumn Width="110" Header="Items" >
    <GridViewColumn.CellTemplate>
        <DataTemplate>
             <WrapPanel DataContext="{Binding Path=Items}" />
        </DataTemplate>
    </GridViewColumn.CellTemplate>
</GridViewColumn>

I attempted to use this code and many variations of it, but i just can't find a way to bind it.

Upvotes: 0

Views: 1223

Answers (1)

brunnerh
brunnerh

Reputation: 185553

WrapPanels don't populate themselves if you set the DataContext, you need an ItemsControl with an ItemsPanel that is a WrapPanel (bind the ItemsSource).

<ItemsControl ItemsSource="{Binding Items}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

Upvotes: 1

Related Questions