From 22cff129f462037765257ee0f91f54b65efa8358 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Thu, 7 Jun 2018 00:28:36 +0200 Subject: [PATCH] Add option to reset sort direction (by clicking on the same column three times) --- ILSpy/Controls/SortableGridViewColumn.cs | 26 ++++++++++++++++-------- ILSpy/SearchPane.xaml | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/ILSpy/Controls/SortableGridViewColumn.cs b/ILSpy/Controls/SortableGridViewColumn.cs index 8c63a840a..0f0b956d6 100644 --- a/ILSpy/Controls/SortableGridViewColumn.cs +++ b/ILSpy/Controls/SortableGridViewColumn.cs @@ -145,10 +145,17 @@ namespace ICSharpCode.ILSpy.Controls GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader; if (grid != null && headerClicked != null && headerClicked.Role != GridViewColumnHeaderRole.Padding) { if (headerClicked.Column == GetCurrentSortColumn(grid)) { - if (GetSortDirection(grid) == ColumnSortDirection.Ascending) - SetSortDirection(grid, ColumnSortDirection.Descending); - else - SetSortDirection(grid, ColumnSortDirection.Ascending); + switch (GetSortDirection(grid)) { + case ColumnSortDirection.None: + SetSortDirection(grid, ColumnSortDirection.Ascending); + break; + case ColumnSortDirection.Ascending: + SetSortDirection(grid, ColumnSortDirection.Descending); + break; + case ColumnSortDirection.Descending: + SetSortDirection(grid, ColumnSortDirection.None); + break; + } } else { SetSortDirection(grid, ColumnSortDirection.Ascending); SetCurrentSortColumn(grid, headerClicked.Column as SortableGridViewColumn); @@ -161,9 +168,9 @@ namespace ICSharpCode.ILSpy.Controls { ColumnSortDirection currentDirection = GetSortDirection(grid); SortableGridViewColumn column = GetCurrentSortColumn(grid); + ICollectionView dataView = CollectionViewSource.GetDefaultView(grid.ItemsSource); + if (column != null && GetSortMode(grid) == ListViewSortMode.Automatic && currentDirection != ColumnSortDirection.None) { - ICollectionView dataView = CollectionViewSource.GetDefaultView(grid.ItemsSource); - string sortBy = column.SortBy; if (sortBy == null) { Binding binding = column.DisplayMemberBinding as Binding; @@ -171,7 +178,7 @@ namespace ICSharpCode.ILSpy.Controls sortBy = binding.Path.Path; } } - + dataView.SortDescriptions.Clear(); if (sortBy != null) { ListSortDirection direction; @@ -181,8 +188,11 @@ namespace ICSharpCode.ILSpy.Controls direction = ListSortDirection.Ascending; dataView.SortDescriptions.Add(new SortDescription(sortBy, direction)); } - dataView.Refresh(); + } else { + dataView.SortDescriptions.Clear(); } + + dataView.Refresh(); } } diff --git a/ILSpy/SearchPane.xaml b/ILSpy/SearchPane.xaml index 90f646b2b..f9fcc0a05 100644 --- a/ILSpy/SearchPane.xaml +++ b/ILSpy/SearchPane.xaml @@ -39,7 +39,7 @@ - +