There is such a ListBoxItem style:
<ListBox Margin="140,0,140,0" ItemsSource="{Binding}"> <ListBox.ItemTemplate> <DataTemplate> <Grid> <Grid.RowDefinitions> <RowDefinition Height="80*"/> <RowDefinition Height="20*"/> </Grid.RowDefinitions> <Image Grid.Row="0" Source="{Binding}"> </Image> <TextBlock Grid.Row="1" Text="{Binding}"> </TextBlock> </Grid> </DataTemplate> </ListBox.ItemTemplate> </ListBox>
and here is the style of the ListBox itself:
<Style TargetType="ListBox"> <Setter Property="SnapsToDevicePixels" Value="true" /> <Setter Property="OverridesDefaultStyle" Value="true" /> <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto" /> <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" /> <Setter Property="ScrollViewer.CanContentScroll" Value="true" /> <Setter Property="MinWidth" Value="120" /> <Setter Property="MinHeight" Value="95" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="ListBox"> <Border Name="Border" BorderThickness="1" CornerRadius="2"> <Border.Background> <SolidColorBrush Color="Transparent" /> </Border.Background> <Border.BorderBrush> <SolidColorBrush Color="Transparent" /> </Border.BorderBrush> <ScrollViewer Margin="0" Focusable="False"> <StackPanel Margin="2" IsItemsHost="True" /> </ScrollViewer> </Border> <ControlTemplate.Triggers> <Trigger Property="IsEnabled" Value="false"> <Setter TargetName="Border" Property="Background"> <Setter.Value> <SolidColorBrush Color="Transparent" /> </Setter.Value> </Setter> <Setter TargetName="Border" Property="BorderBrush"> <Setter.Value> <SolidColorBrush Color="Transparent" /> </Setter.Value> </Setter> </Trigger> <Trigger Property="IsGrouping" Value="True"> <Setter Property="ScrollViewer.CanContentScroll" Value="False" /> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
Like instead
<ScrollViewer Margin="0" Focusable="False"> <StackPanel Margin="2" IsItemsHost="True" /> </ScrollViewer>
I think to do
<ScrollViewer Margin="0" Focusable="False"> <WrapPanel Margin="2" IsItemsHost="True" /> </ScrollViewer>
But the problem is that it automatically calculates so many elements enters horizontally and inserts and I only need 4 horizontally. Tell me how to implement it.