My Listview:
<ListView ItemTemplate="{StaticResource GridViewItemTemplate}" Name="gridView_movies">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
Datatemplate of the list:
<DataTemplate x:Key="GridViewItemTemplate">
<StackPanel Orientation="Vertical" >
<Image Width="250" Height="290" Source="{Binding Image}"/>
<TextBlock Text="{Binding Title}" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="20"/>
</StackPanel>
</DataTemplate>
When i load this, all items are showed in one row, my question is, How can i show only 3 items per row instead of all items in one row.
Thanks for the attention.
Use
<UniformGrid Columns="3" .../>
instead of <StackPanel Orientation="Horizontal" .../>
in ItemsPanelTemplate
Use a WrapPanel
instead of a StackPanel
. It doesn't allow you to directly specify the number of items per row, but you can set the width of each item, which is almost as good. When there is no space left on a row, it continues on the next row.
EDIT: you could also use a UniformGrid
, as suggested by Bonial. The drawback is that if you can resize your UI and make the ListView
wider, the number of items per row won't change, and they will be stretched to fill the space. Depending on what you want, it might be OK, but I think WrapPanel
is a better option in most cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With