wpfxaml.net-4.0itemscontrol

Item spacing in WPF ItemsControl


I'm displaying a List<string> collection in an ItemsControl. The problem is that there is no spacing between the list items such as TheyAreAllNextToEachOther.

How can I create some spacing between the items?

<ItemsControl Grid.Column="2" 
         Grid.ColumnSpan="2" 
         ItemsSource="{Binding Path=ShowTimes}"
         BorderThickness="0">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <WrapPanel IsItemsHost="True" Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

Solution

  • I'd add an ItemTemplate where you set the margin

    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBlock Margin="3,3,3,3" Text="{Binding}"/>
       </DataTemplate>
    </ItemsControl.ItemTemplate>