@@ -42,6 +42,7 @@ public partial class TableViewColumnHeader : ContentControl
42
42
private bool _resizeStarted ;
43
43
private double _resizeStartingWidth ;
44
44
private bool _resizePreviousStarted ;
45
+ private TextBox ? _searchBox ;
45
46
46
47
/// <summary>
47
48
/// Initializes a new instance of the TableViewColumnHeader class.
@@ -125,10 +126,17 @@ private void ClearFilter()
125
126
/// </summary>
126
127
private void ApplyFilter ( )
127
128
{
128
- if ( _tableView is not null )
129
+ if ( _selectAllCheckBox ? . IsChecked is true && string . IsNullOrEmpty ( _searchBox ? . Text ) )
129
130
{
130
- _tableView . FilterHandler . SelectedValues [ Column ! ] = _optionsFlyoutViewModel . SelectedValues ;
131
- _tableView . FilterHandler ? . ApplyFilter ( Column ! ) ;
131
+ ClearFilter ( ) ;
132
+ }
133
+ else if ( _tableView is not null )
134
+ {
135
+ _optionsFlyoutViewModel . SelectedValues = [ .. _optionsFlyoutViewModel . FilterItems . Where ( x => x . IsSelected ) . Select ( x => x . Value ) ] ;
136
+ {
137
+ _tableView . FilterHandler . SelectedValues [ Column ! ] = _optionsFlyoutViewModel . SelectedValues ;
138
+ _tableView . FilterHandler ? . ApplyFilter ( Column ! ) ;
139
+ }
132
140
}
133
141
}
134
142
@@ -186,7 +194,7 @@ protected override void OnApplyTemplate()
186
194
}
187
195
188
196
_optionsFlyout . Opening += OnOptionsFlyoutOpening ;
189
- _optionsFlyout . Closed += ( s , e ) => _optionsFlyoutViewModel . ClearFilterText ( ) ;
197
+ _optionsFlyout . Closed += OnOptionsFlyoutClosed ;
190
198
_optionsButton . Tapped += OnOptionsButtonTaped ;
191
199
_optionsButton . DataContext = _optionsFlyoutViewModel = new OptionsFlyoutViewModel ( _tableView , this ) ;
192
200
@@ -208,26 +216,39 @@ protected override void OnApplyTemplate()
208
216
}
209
217
#endif
210
218
211
- if ( menuItem ? . FindDescendant < AutoSuggestBox > ( x => x . Name == "SearchBox" ) is { } searchBox )
219
+ if ( menuItem ? . FindDescendant < TextBox > ( x => x . Name == "SearchBox" ) is { } searchBox )
212
220
{
213
- searchBox . PlaceholderText = TableViewLocalizedStrings . SearchBoxPlaceholder ;
221
+ _searchBox = searchBox ;
222
+ _searchBox . PlaceholderText = TableViewLocalizedStrings . SearchBoxPlaceholder ;
223
+ _searchBox . TextChanged += OnSearchBoxTextChanged ;
214
224
#if WINDOWS
215
- searchBox . PreviewKeyDown += OnSearchBoxKeyDown ;
225
+ _searchBox . PreviewKeyDown += OnSearchBoxKeyDown ;
216
226
#else
217
- searchBox . KeyDown += OnSearchBoxKeyDown ;
227
+ _searchBox . KeyDown += OnSearchBoxKeyDown ;
218
228
#endif
219
229
}
220
230
221
231
SetFilterButtonVisibility ( ) ;
222
232
EnsureGridLines ( ) ;
223
233
}
224
234
235
+ /// <summary>
236
+ /// Handles the TextChanged event for the search box.
237
+ /// </summary>
238
+ private void OnSearchBoxTextChanged ( object sender , TextChangedEventArgs e )
239
+ {
240
+ if ( _tableView ? . FilterHandler is not null )
241
+ {
242
+ _optionsFlyoutViewModel . FilterItems = _tableView . FilterHandler . GetFilterItems ( Column ! , _searchBox ! . Text ) ;
243
+ }
244
+ }
245
+
225
246
/// <summary>
226
247
/// Handles the KeyDown event for the search box.
227
248
/// </summary>
228
249
private void OnSearchBoxKeyDown ( object sender , KeyRoutedEventArgs e )
229
250
{
230
- if ( e . Key == VirtualKey . Enter && _optionsFlyoutViewModel is { FilterText . Length : > 0 } )
251
+ if ( e . Key == VirtualKey . Enter && _searchBox ? . Text . Length > 0 )
231
252
{
232
253
_optionsFlyoutViewModel . OkCommand . Execute ( null ) ;
233
254
@@ -256,12 +277,29 @@ private void OnSelectAllCheckBoxUnchecked(object sender, RoutedEventArgs e)
256
277
/// <summary>
257
278
/// Handles the Opening event for the options flyout.
258
279
/// </summary>
259
- private void OnOptionsFlyoutOpening ( object ? sender , object e )
280
+ private async void OnOptionsFlyoutOpening ( object ? sender , object e )
260
281
{
261
282
if ( _tableView ? . FilterHandler is not null )
262
283
{
263
284
_optionsFlyoutViewModel . FilterItems = _tableView . FilterHandler . GetFilterItems ( Column ! , null ) ;
264
285
}
286
+
287
+ if ( _searchBox is not null )
288
+ {
289
+ await Task . Delay ( 100 ) ;
290
+ await FocusManager . TryFocusAsync ( _searchBox , FocusState . Programmatic ) ;
291
+ }
292
+ }
293
+
294
+ /// <summary>
295
+ /// Handles the Closed event for the options flyout.
296
+ /// </summary>
297
+ private void OnOptionsFlyoutClosed ( object ? sender , object e )
298
+ {
299
+ if ( _searchBox is not null )
300
+ {
301
+ _searchBox . Text = string . Empty ;
302
+ }
265
303
}
266
304
267
305
/// <summary>
0 commit comments