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
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.