WPF DataGrid: Automatically re-sort on a DataGridTemplateColumn WPF DataGrid: Automatically re-sort on a DataGridTemplateColumn wpf wpf

WPF DataGrid: Automatically re-sort on a DataGridTemplateColumn


I'm also looking the answer to this. I found one solution: (not happy with it but...)

When your collection is updated you can do this:

SortDescription sortDescription = grdData.Items.SortDescriptions[0];grdData.ItemsSource = null;grdData.ItemsSource = Data;grdData.Items.SortDescriptions.Add(sortDescription);

Ugly but it does work. You will want to store the whole collection unlike my example that does just first item.

One problem with it though is that the DataGrid looses the header that indicates the sort, so although it resorts correctly the column header is no longer selected with the arrow showing the direction of the sort.


I know this is old but also I got this DataGridTemplateColumn re-sort problem. This does not happen on DataGridTextColumn. The way I fix it with intact sort direction on column header is:

// after updating the collection, remove all SortDescription and add'em back.SortDescriptionCollection sortDescriptions = new SortDescriptionCollection();foreach (SortDescription sd in dataGrid.Items.SortDescriptions){    sortDescriptions.Add(sd);}dataGrid.Items.SortDescriptions.Clear();foreach (SortDescription sd in sortDescriptions){    dataGrid.Items.SortDescriptions.Add(sd);}

Hope this helps people.


None of theses answers worked for me in 2016.

After some try&error I came up with this and it seems to work just fine:

dataGrid.Items.IsLiveSorting = true;