Prevent user from resizing columns with WPF ListView

For those looking for a quicker and simpler answer.

Set IsEnabled to False in the ColumnHeaderContainerStyle. This will prevent the user from resizing.

Like this:

<GridView.ColumnHeaderContainerStyle>
  <Style TargetType="{x:Type GridViewColumnHeader}">
       <Setter Property="IsEnabled" Value="False"/>
  </Style>
</GridView.ColumnHeaderContainerStyle>

If you want to fix the disabled grayed out color add a trigger on the IsEnabled property and fix what you need.

<GridView.ColumnHeaderContainerStyle>
   <Style TargetType="{x:Type GridViewColumnHeader}">
       <Setter Property="IsEnabled" Value="False"/>
    <Style.Triggers>
       <Trigger Property="IsEnabled" Value="False">                
          <Setter Property="TextElement.Foreground" Value="Black"/>                       
       </Trigger>
    </Style.Triggers>
  </Style>
</GridView.ColumnHeaderContainerStyle>

This answer might not be as elegant as other posted; but in my case all I needed was a quick way of doing it.

Hope this helps someone.

Leave a Comment