How to stretch the width of ListView elements to fill the parent container?

How to stretch the width of list items to fill the parent container?

The default behavior seems to compress everything as narrow as possible.

+4
source share
1 answer

The problem is not the child, but the item container, which has HorizontalAlignment = Left, hidden somewhere deep inside the frame code. Only after fixing this will you get the behavior that you would expect 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>
+22
source

Source: https://habr.com/ru/post/1545976/


All Articles