直接上正确代码:
1 <ListView x:Name="lv_product" HorizontalContentAlignment="Stretch" ItemsSource="{Binding Products}" 2 ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible" 3 BorderBrush="Transparent" Background="Transparent"> 4 5 <ListView.ItemsPanel> 6 <ItemsPanelTemplate> 7 <WrapPanel Orientation="Horizontal" FlowDirection="LeftToRight" ></WrapPanel> 8 </ItemsPanelTemplate> 9 </ListView.ItemsPanel> 10 <ListView.ItemTemplate> 11 <DataTemplate> 12 <StackPanel> 13 <Image Source="{Binding PicturePath}" Width="80" Height="80"/> 14 <TextBlock Text="{Binding ProductName}" HorizontalAlignment="Center"/> 15 </StackPanel> 16 </DataTemplate> 17 </ListView.ItemTemplate> 18 </ListView>View Code
注意上面的 ScrollViewer.HorizontalScrollBarVisibility="Disabled" 这个设置很关键。因为ListView自带横向和纵向滚动条,必须关了自带的滚动条后WrapPanel的滚动才会起作用。
标签:换行,ItemsPanel,滚动条,WPF,ListView,WrapPanel From: https://www.cnblogs.com/follow-discoverer/p/18516298