列表框中的WPF包装

列表框中的WPF包装,wpf,listview,wrappanel,Wpf,Listview,Wrappanel,我想在垂直滚动列表中显示多个图像,但这些图像被细分为几个组,用户必须能够区分这些组。为了实现这一点,我使用了一个ListView,其中的项目包含一个WrapPanel,其中包含单个图像: <ListView Name="ListGroups" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> <ListView.ItemTemplate> <DataTemplate>

我想在垂直滚动列表中显示多个图像,但这些图像被细分为几个组,用户必须能够区分这些组。为了实现这一点,我使用了一个ListView,其中的项目包含一个WrapPanel,其中包含单个图像:

<ListView Name="ListGroups" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical">
                <Label Content="{Binding Groupname}" />
                <ListBox ItemsSource="{Binding Images}" >
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel  />
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical">
                                <Image Source="{Binding Thumb}" />
                                <Label Content="{Binding Res}" />
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
我得到的是:

但我想实现的是:


也就是说,我根本不想要任何水平的横杆,而且这些组显然必须分开。另一方面,调整窗口大小时,一个组中的图像必须换行以填充所有可用空间。

只需禁用内部列表框的水平滚动条,并在图像元素上设置Stretch=None

<ListView ... ScrollViewer.HorizontalScrollBarVisibility="Disabled">
    <ListView.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <Label Content="{Binding Groupname}"/>
                <ListBox ItemsSource="{Binding Images}"
                         ScrollViewer.HorizontalScrollBarVisibility="Disabled" >
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <WrapPanel/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <Image Source="{Binding Thumb}" Stretch="None"/>
                                <Label Content="{Binding Res}"/>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </StackPanel>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

谢谢你的回答,但事实上我已经试过了。然后,所有图像水平拉伸以填充窗口的整个水平宽度。然后将其拉伸属性设置为“无”或设置固定宽度。请参见编辑后的答案。