1212using System . Threading . Tasks ;
1313using Windows . System ;
1414using Windows . UI . Core ;
15+ using WinUI . TableView . Collections ;
1516using WinUI . TableView . Extensions ;
1617using SD = WinUI . TableView . SortDirection ;
1718
@@ -97,28 +98,23 @@ private void DoSort(SD? direction, bool singleSorting = true)
9798 {
9899 if ( CanSort && Column is not null && _tableView is { CollectionView : CollectionView { } collectionView } )
99100 {
100- var defer = collectionView . DeferRefresh ( ) ;
101+ using var defer = collectionView . DeferRefresh ( ) ;
102+ if ( singleSorting )
101103 {
102- if ( singleSorting )
103- {
104- _tableView . ClearAllSortingWithEvent ( ) ;
105- }
106- else
107- {
108- ClearSortingWithEvent ( ) ;
109- }
110-
111- if ( direction is not null )
112- {
113- var boundColumn = Column as TableViewBoundColumn ;
114- Column . SortDirection = direction ;
115- _tableView . SortDescriptions . Add (
116- new ColumnSortDescription ( Column ! , boundColumn ? . PropertyPath , direction . Value ) ) ;
117-
118- _tableView . EnsureAlternateRowColors ( ) ;
119- }
104+ _tableView . ClearAllSortingWithEvent ( ) ;
105+ }
106+ else
107+ {
108+ ClearSortingWithEvent ( ) ;
109+ }
110+
111+ if ( direction is not null )
112+ {
113+ var boundColumn = Column as TableViewBoundColumn ;
114+ Column . SortDirection = direction ;
115+ _tableView . SortDescriptions . Add (
116+ new ColumnSortDescription ( Column ! , boundColumn ? . PropertyPath , direction . Value ) ) ;
120117 }
121- defer . Complete ( ) ;
122118 }
123119 }
124120
@@ -135,11 +131,12 @@ private void ClearSortingWithEvent()
135131 return ;
136132 }
137133
138- if ( CanSort && _tableView is not null && Column is not null )
134+ if ( CanSort && _tableView ? . CollectionView is CollectionView { } collectionView && Column is not null )
139135 {
136+ using var defer = collectionView . DeferRefresh ( ) ;
140137 _tableView . DeselectAll ( ) ;
141138 Column . SortDirection = null ;
142- _tableView . SortDescriptions . RemoveWhere ( x => x is ColumnSortDescription columnSort && columnSort . Column == Column ) ;
139+ collectionView . SortDescriptions . RemoveWhere ( x => x is ColumnSortDescription columnSort && columnSort . Column == Column ) ;
143140 }
144141 }
145142
@@ -163,10 +160,10 @@ private void ApplyFilter()
163160 else if ( _tableView is not null )
164161 {
165162 _optionsFlyoutViewModel . SelectedValues = GetSelectedValues ( ) ;
166- _tableView . FilterHandler . SelectedValues [ Column ! ] = _optionsFlyoutViewModel . SelectedValues ;
167- _tableView . FilterHandler ? . ApplyFilter ( Column ! ) ;
168- }
163+ _tableView . FilterHandler . SelectedValues [ Column ! ] = _optionsFlyoutViewModel . SelectedValues ;
164+ _tableView . FilterHandler ? . ApplyFilter ( Column ! ) ;
169165 }
166+ }
170167
171168 private ICollection < object ? > GetSelectedValues ( )
172169 {
0 commit comments