Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 688
JumpyStackOverflow Avatar asked Jun 25 '14 10:06

JumpyStackOverflow


1 Answers

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>
like image 94
JumpyStackOverflow Avatar answered Oct 10 '22 05:10

JumpyStackOverflow