views:

566

answers:

1

I'm trying to get sorting to work with a WPF Toolkit DataGrid. My DataGrid's rows are instances of view models. The row's view model exposes a view model for each column. Each column is data templated to a different user control. This is what my DataGrid's column declarations look like:

<tk:DataGrid.Columns>
    <tk:DataGridTemplateColumn Header="Name" MinWidth="150" Width="150">
        <tk:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <ContentPresenter Content="{Binding Path=NameViewModel}"/>
            </DataTemplate>
        </tk:DataGridTemplateColumn.CellTemplate>
    </tk:DataGridTemplateColumn>
    <tk:DataGridTemplateColumn Header="Data Dependencies" MinWidth="350" Width="Auto">
        <tk:DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
                <ContentPresenter Content="{Binding Path=DependenciesViewModel}"/>
            </DataTemplate>
        </tk:DataGridTemplateColumn.CellTemplate>
    </tk:DataGridTemplateColumn>
</tk:DataGrid.Columns>

Name is bound to a view model that is data templated with a user control that displays the name as a text block. It also displays some other graphical information, which is why it's displayed in a user control.

The problem with doing it this way is that I lose the ability to sort the Name column. I was hoping that implementing IComparable<T> on the row view model that exposes the Name view model would do the trick, but it doesn't look like the WPF data grid cares that it implements IComparable<T>.

Does anyone have any suggestions as to how best to tackle this?

A: 

This answer was what I was looking for.

unforgiven3