Search code examples
listviewwinrt-xamlwindows-phone-8.1fill-parent

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.


Solution

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