Search code examples
wpfxamlcommandparameter

WPF CommandParameter GridViewColumnHeader


my question is: Is it possible to use a GridViewColumnHeader as a CommandParameter? I have the following code and I want to use the clicked ColumnHeader as the CommandParameter:

<GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Path=Vorname}">
      <GridViewColumnHeader Content="Vorname" Command="{Binding Path=ColumnHeaderClickCommand}"/>
</GridViewColumn>

Solution

  • If ColumnHeaderClickCommand is an ICommand:

    <GridViewColumn Width="Auto" DisplayMemberBinding="{Binding Path=Vorname}">
         <GridViewColumnHeader Content="Vorname" Command="{Binding Path=ColumnHeaderClickCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self}}"/>
    </GridViewColumn>