Fill Grid width inside a listbox

后端 未结 1 1586
悲&欢浪女
悲&欢浪女 2020-12-06 10:11

I have a grid as the datatemplate for items in a listbox and it\'s not filling the whole width of the control. I have tried the suggestions in the other questions but they a

相关标签:
1条回答
  • 2020-12-06 10:41

    You need to make the ListBoxItems stretch their content, either by changing the respective property on the ListBox:

    <ListBox HorizontalContentAlignment="Stretch" ...>
    

    ...or by setting it on the items via the ItemContainerStyle:

    <ListBox.ItemContainerStyle>
        <Style TargetType="{x:Type ListBoxItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        </Style>
    </ListBox.ItemContainerStyle>
    

    By default both will work as the ListBoxItem default style binds the HorizontalContentAlignment property to the owning ListBox's property.

    0 讨论(0)
提交回复
热议问题