How to add padding inbetween items in a WPF ListView?
listview, wpf
Solution
You can set a `Padding` in the `ItemContainerStyle` of the `ListView`. You can use a `DataTrigger` on `RelativeSource PreviousData` being `null` to make it conditional.
Alternatively you could create a new `Panel` which has a concept of spacing.
Problem
I have a horizontal ListView which I would like to ensure that there is some padding between the items (in my case I have Grid inside of the item template), but I don't want there to be any extra padding for the last grid I want there to be padding where the red line is. EDIT H.B.'s suggestion was really helpful, here is the style that I added to get a 5px margin between grids... ``` <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Setter Property="Margin" Value="5 0 0 0" /> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}"> <Setter Property="Margin" Value="0" /> </DataTrigger> </Style.Triggers> </Style> </ListView.ItemContainerStyle> ```