How can I sort a DataGridTemplateColumn on a WPF Toolkit DataGrid?

Posted by Kilhoffer on Stack Overflow See other posts from Stack Overflow or by Kilhoffer
Published on 2010-04-29T17:13:51Z Indexed on 2010/04/29 17:17 UTC
Read the original article Hit count: 1005

I have a WPF Toolkit DataGrid with one DataGridTemplateColumn. I've specified in a grid attribute that I wish all columns to be sortable, but the DataGridTemplateColumn won't allow it. All other columns do allow sorting. I've even tried explicitly setting CanUserSort to true for that column, but no luck. Is it even possible to sort a template column? I've provided a custom sorter that works for all columns, but the header won't allow a sort click.

<Controls:DataGrid ItemsSource="{Binding Events}" AutoGenerateColumns="False" 
                               CanUserSortColumns="True" 
                               CanUserReorderColumns="False" 
                               Sorting="DataGrid_Sorting" 
                               x:Name="EventsGrid">
                <Controls:DataGrid.Columns>
                    <Controls:DataGridTemplateColumn Header="Type" Width="42" CanUserResize="False">
                        <Controls:DataGridTemplateColumn.CellTemplate>
                            <DataTemplate>
                                <Image Source="{Binding EventTypeImage, Mode=OneWay}" HorizontalAlignment="Center" Width="16"/>
                            </DataTemplate>
                        </Controls:DataGridTemplateColumn.CellTemplate>
                    </Controls:DataGridTemplateColumn>
                    <Controls:DataGridTextColumn Header="Source" 
                                           Binding="{Binding Source, Mode=OneWay}" />
                    <Controls:DataGridTextColumn Header="Details" MinWidth="175" 
                                           Binding="{Binding Details, Mode=OneWay}" />
                    <Controls:DataGridTextColumn Header="Timestamp" MinWidth="175"  
                                           Binding="{Binding Timestamp, Mode=OneWay}" 
                                           IsReadOnly="True"/>
                </Controls:DataGrid.Columns>
            </Controls:DataGrid>

© Stack Overflow or respective owner

Related posts about wpf

Related posts about wpftoolkit