DataGrid : Binding Command to Column Sorting

Dec 20, 2008 at 12:04 AM
Edited Dec 20, 2008 at 12:06 AM

I woudl like to bind a command to the DataGridColumnHeader using a custom ColumnHeaderStyle

Following the DM-V-VM pattern of Dan Crevier's Blog I defined a ViewModel with a SortColumnCommand Parameter (type RoutedCommand), set the DataContext of the DataGrid to the ViewModel object and defined a setter in the style 


<Style x:Key="MyHeader" TargetType="{x:Type toolkit:DataGridColumnHeader}">
    <Setter Property="Command" Value="{Binding SortColumnCommandModel.Command}"/>
    <Setter Property="local:CreateCommandBinding.Command" Value="{Binding SortColumnCommandModel}"/>

The setter seems not to understand the DataContext and gives binding errors.

Any obvious mistakes in what I try to do here ?
Any ideas how to bind a command to the DataGridColumnHeader ?







Jan 7, 2009 at 12:51 PM
Try the technic on forwarding the DataContext that Jaime describes here,