Reputation: 720
How to stretch listview items width to fill parent container?
The default behaviour seems to be squishing everything as narrow as possible.
Upvotes: 6
Views: 5916
Reputation: 720
The problem is not with the child item but with the itemcontainer which has a HorizontalAlignment=Left hidden somewhere deep inside the framework code. Only after fixing this will you get the behaviour one would expect to be there by default.
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<GroupStyle.HeaderContainerStyle >
<Style TargetType="ListViewHeaderItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</GroupStyle.HeaderContainerStyle>
Upvotes: 26