WrapPanel不会在WPF的ListView包装 [英] WrapPanel doesn't wrap in WPF ListView
问题描述
我使用一个ListView像这样一个ItemTemplate:
I am using a ListView with an ItemTemplate like this:
<Window.Resources>
<DataTemplate x:Key="ItemTemplate">
<WrapPanel Orientation="Horizontal">
<Image Width="50" Height="50" Stretch="Fill" Source="{Binding Cover}"/>
<Label Content="{Binding Title}" />
</WrapPanel>
</DataTemplate>
</Window.Resources>
但封面不填补像Windows资源管理器窗口在屏幕上。
But the Covers do not fill the screen like windows explorer windows.
我如何做到这一点?他们只是在我的版本垂直堆叠。
How do I do this? They just get stacked vertically in my version.
推荐答案
尝试usinga WrapPanel作为ListView的项目小组,并禁用水平滚动条:
Try usinga WrapPanel as your ListView's item panel and disable the horizontal scrollbar:
<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
...
</ListView>
更新:itowlson表明,这种解释让事情更清晰:ItemTemplate中指定每个项目应该如何呈现。它有项目布局方式无影响。 ItemsPanel,相比之下,不指定布局
Update: itowlson suggests this explanation to make things clearer: ItemTemplate specifies how each item should be rendered. It has no effect on how items are laid out. ItemsPanel, by contrast, does specify the layout.
此外,您可能需要的所有项目大小相同。你可以找出如何做到这一点从这篇文章:<一href=\"http://joshsmithonwpf.word$p$pss.com/2008/09/06/synchronizing-the-width-of-elements-in-an-itemscontrol/\">http://joshsmithonwpf.word$p$pss.com/2008/09/06/synchronizing-the-width-of-elements-in-an-itemscontrol/
Also, you may want all items to be displayed the same size. You can find out how to do that from this article: http://joshsmithonwpf.wordpress.com/2008/09/06/synchronizing-the-width-of-elements-in-an-itemscontrol/
这篇关于WrapPanel不会在WPF的ListView包装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!