Skip to content

Commit d683d7d

Browse files
authored
Merge pull request #167 from w-ahmad/defer_refresh_on_sort
added defer refresh on sorting to keep h scroll offset
2 parents e002af1 + 1732672 commit d683d7d

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

src/TableViewColumnHeader.cs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -70,25 +70,30 @@ private void OnWidthChanged(DependencyObject sender, DependencyProperty dp)
7070
/// </summary>
7171
private void DoSort(SD? direction, bool singleSorting = true)
7272
{
73-
if (CanSort && Column is not null && _tableView is not null)
73+
if (CanSort && Column is not null && _tableView is { CollectionView: CollectionView { } collectionView })
7474
{
75-
if (singleSorting)
75+
var defer = collectionView.DeferRefresh();
7676
{
77-
_tableView.ClearAllSortingWithEvent();
77+
if (singleSorting)
78+
{
79+
_tableView.ClearAllSortingWithEvent();
80+
}
81+
else
82+
{
83+
ClearSortingWithEvent();
84+
}
85+
86+
if (direction is not null)
87+
{
88+
var boundColumn = Column as TableViewBoundColumn;
89+
Column.SortDirection = direction;
90+
_tableView.SortDescriptions.Add(
91+
new ColumnSortDescription(Column!, boundColumn?.PropertyPath, direction.Value));
92+
93+
_tableView.EnsureAlternateRowColors();
94+
}
7895
}
79-
else
80-
{
81-
ClearSortingWithEvent();
82-
}
83-
84-
if (direction is null) return;
85-
86-
var boundColumn = Column as TableViewBoundColumn;
87-
Column.SortDirection = direction;
88-
_tableView.SortDescriptions.Add(
89-
new ColumnSortDescription(Column!, boundColumn?.PropertyPath, direction.Value));
90-
91-
_tableView.EnsureAlternateRowColors();
96+
defer.Complete();
9297
}
9398
}
9499

@@ -222,7 +227,7 @@ protected override void OnApplyTemplate()
222227
_searchBox.PlaceholderText = TableViewLocalizedStrings.SearchBoxPlaceholder;
223228
_searchBox.TextChanged += OnSearchBoxTextChanged;
224229
#if WINDOWS
225-
_searchBox.PreviewKeyDown += OnSearchBoxKeyDown;
230+
_searchBox.PreviewKeyDown += OnSearchBoxKeyDown;
226231
#else
227232
_searchBox.KeyDown += OnSearchBoxKeyDown;
228233
#endif

0 commit comments

Comments
 (0)