Here's my XAML:
<ListBox Grid.Row="1" x:Name="lstGames" Background="#343434" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="{Binding ImageUrl}" Width="100"/>
<StackPanel Grid.Column="1">
<StackPanel Orientation="Horizontal">
<TextBlock Text="Title:" />
<TextBlock Text="{Binding Title}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Release Date:" />
<TextBlock Text="{Binding ReleaseDate}" />
</StackPanel>
</StackPanel>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Sans putting a Rectangle and giving it a color inside of the DataTemplate, does the ListBox have some way of natively setting something in between every item?
This builds on the answer @EvaLacy gave to be a little more complete.
Because that answer replaces the template of the
ListBoxItem
, it disables the built-in highlighting that occurs when selecting a list item (because the highlighting is done via triggers in the original template). To get this functionality back, put the default triggers into the new template and tweak the template content a bit:I retrieved these triggers using the old but useful Show Me the Template application.
This is a better example because then you don't have a separator at the top
You can move the presentation of the separator into the
ListBoxItem
control template as in this intentionally simplified example:This keeps the separator out of your item template. The trade off is that you may need to copy more from the default
ListViewItem
control template to meet your needs. Of course theSeparator
is one of only a dozen ways to visually render the separator.My solution: