Joa*_*nge 48 .net c# wpf listview
我正在使用ListView和ItemTemplate,如下所示:
<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>
Run Code Online (Sandbox Code Playgroud)
但封面不像Windows资源管理器窗口那样填满屏幕.
我该怎么做呢?它们只是在我的版本中垂直堆叠.
替代文字http://www.functionx.com/visualc/applications/images/explorer1.gif
Gro*_*kys 113
尝试使用WrapPanel作为ListView的项目面板并禁用水平滚动条:
<ListView ScrollViewer.HorizontalScrollBarVisibility="Disabled">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
...
</ListView>
Run Code Online (Sandbox Code Playgroud)
更新:itowlson建议这个解释使事情更清楚:ItemTemplate指定每个项目应该如何呈现.它对物品的布局方式没有影响.相比之下,ItemsPanel确实指定了布局.
此外,您可能希望所有项目都显示相同的大小.你可以从这篇文章中找到如何做到这一点:http://joshsmithonwpf.wordpress.com/2008/09/06/synchronizing-the-width-of-elements-in-an-itemscontrol/