private void GridViewColumnHeader_Click(object sender, RoutedEventArgs e) { var column = sender as GridViewColumnHeader; var sort_by = column.Tag.ToString(); var listview_files = WindowUtils.FindParent <ListView>(column); if (this.listview_sort_column != null) { AdornerLayer.GetAdornerLayer(this.listview_sort_column).Remove(this.listview_sort_adorner); listview_files.Items.SortDescriptions.Clear(); } ListSortDirection direction = ListSortDirection.Ascending; if (this.listview_sort_column == column && this.listview_sort_adorner.Direction == direction) { direction = ListSortDirection.Descending; } this.listview_sort_column = column; this.listview_sort_adorner = new SortAdorner(this.listview_sort_column, direction); AdornerLayer.GetAdornerLayer(this.listview_sort_column).Add(this.listview_sort_adorner); listview_files.Items.SortDescriptions.Add(new SortDescription(sort_by, direction)); }