将换行面板添加到列表视图项

本文关键字:列表 视图 添加 换行 | 更新日期: 2023-09-27 18:21:59

我在互联网上找了很多遍,但都找不到问题的答案。

我希望能够有一个包含两列的列表视图,一列包含文本,另一列包含可将图像拖动到的环绕面板。

我目前正在将listview绑定到一个数据集,因此所述数据集的列由WPF列拾取。

<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>

我试图使用这个代码和它的许多变体,但我就是找不到绑定它的方法。

将换行面板添加到列表视图项

如果设置DataContext,则WrapPanels不会自行填充,您需要一个ItemsControl和一个作为WrapPanelItemsPanel(绑定ItemsSource)。

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