JumpyStackOverflow
JumpyStackOverflow

Reputation: 720

How to stretch ListView items width to fill parent container?

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

Answers (1)

JumpyStackOverflow
JumpyStackOverflow

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. Before and after screenshots showing both the problem and the solution

<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

Related Questions