I was doing WPF project with MVVM design pattern. There I used a DataGridView to show my data as a table. But I needed to sort the data in the grid, with my own algorithm instead of using the default sorting. Therefore I needed to bind a command to the header. I did not know any anwer to do that. While searching on the internet I found this answer.
I just had to add these line inside the style of DataGrid Header.
1 2 3 4 5 6 7 | <style targettype="{x:Type DataGridColumnHeader}"> <setter Property="Command" Value="{Binding MyCommand}"/> <setter Property="CommandParameter" Value="{Binding Path=Content, RelativeSource={RelativeSource Self}}"/> ... </style> |