简体   繁体   中英

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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM