Item spacing in WPF ItemsControl

后端 未结 2 894
后悔当初
后悔当初 2021-02-07 08:34

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

相关标签:
2条回答
  • 2021-02-07 09:00

    I'd add an ItemTemplate where you set the margin

    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <TextBlock Margin="3,3,3,3" Text="{Binding}"/>
       </DataTemplate>
    </ItemsControl.ItemTemplate>
    
    0 讨论(0)
  • 2021-02-07 09:11

    Provide style to your ItemsControl containers (default ContentPresenter) like this where you can set Margin to say 5:

        <ItemsControl>
            <ItemsControl.ItemContainerStyle>
                <Style>
                    <Setter Property="FrameworkElement.Margin" Value="5"/>
                </Style>
            </ItemsControl.ItemContainerStyle>
        </ItemsControl>
    
    0 讨论(0)
提交回复
热议问题