@@ -37,17 +37,15 @@ public partial class TableViewColumnHeader : ContentControl
3737 private TableView ? _tableView ;
3838 private TableViewHeaderRow ? _headerRow ;
3939 private Button ? _optionsButton ;
40- private MenuFlyout ? _optionsFlyout ;
41- private MenuFlyoutItem ? _filterItemsMenuItem ;
40+ private TableViewFilterMenuFlyout ? _optionsFlyout ;
4241 private ContentPresenter ? _contentPresenter ;
4342 private Rectangle ? _v_gridLine ;
4443 private bool _resizeStarted ;
4544 private double _resizeStartingWidth ;
4645 private bool _resizePreviousStarted ;
4746 private double _reorderStartingPosition ;
4847 private bool _reorderStarted ;
49- private RenderTargetBitmap ? _dragVisuals ;
50- private TableViewFilterItemsControl ? _filterItemsControl ;
48+ private RenderTargetBitmap ? _dragVisuals ;
5149
5250 /// <summary>
5351 /// Initializes a new instance of the TableViewColumnHeader class.
@@ -156,9 +154,9 @@ private void ClearFilter()
156154 /// <summary>
157155 /// Applies the filter for the column.
158156 /// </summary>
159- private void ApplyFilter ( )
157+ internal void ApplyFilter ( )
160158 {
161- var shouldApplyFilter = _filterItemsControl ? . ShouldApplyFilter ?? false ;
159+ var shouldApplyFilter = FilterItemsControl ? . ShouldApplyFilter ?? false ;
162160
163161 if ( ! shouldApplyFilter && ( Column ? . IsFiltered ?? false ) )
164162 {
@@ -173,7 +171,7 @@ private void ApplyFilter()
173171
174172 private ICollection < object ? > GetSelectedValues ( )
175173 {
176- var filterItems = _filterItemsControl ? . FilterItems ?? [ ] ;
174+ var filterItems = FilterItemsControl ? . FilterItems ?? [ ] ;
177175 var selectedValues = filterItems . Where ( x => x . IsSelected ) . Select ( x => x . Value ) ;
178176 var firstItem = selectedValues . FirstOrDefault ( x => x is not null ) ;
179177 var firstItemType = firstItem ? . GetType ( ) ;
@@ -197,7 +195,7 @@ private void ApplyFilter()
197195 /// <summary>
198196 /// Hides the options flyout.
199197 /// </summary>
200- private void HideFlyout ( )
198+ internal void HideFlyout ( )
201199 {
202200 _optionsFlyout ? . Hide ( ) ;
203201 }
@@ -231,20 +229,16 @@ protected override void OnApplyTemplate()
231229 {
232230 base . OnApplyTemplate ( ) ;
233231
234- _optionsFlyout ? . Opening - = OnOptionsFlyoutOpening ;
235- _optionsFlyout ? . Closed - = OnOptionsFlyoutClosed ;
236232 _optionsButton ? . Tapped - = OnOptionsButtonTaped ;
237- _filterItemsMenuItem ? . PreviewKeyUp - = OnFilterItemsMenuItemPreviewKeyUp ;
238233
239- _filterItemsControl ? . FilterItems = null ;
240- _filterItemsControl ? . TableView = null ;
241- _filterItemsControl ? . ColumnHeader = null ;
242- _filterItemsControl = null ;
234+ FilterItemsControl ? . FilterItems = null ;
235+ FilterItemsControl ? . TableView = null ;
236+ FilterItemsControl ? . ColumnHeader = null ;
237+ FilterItemsControl = null ;
243238 _tableView = this . FindAscendant < TableView > ( ) ;
244239 _headerRow = this . FindAscendant < TableViewHeaderRow > ( ) ;
245240 _optionsButton = GetTemplateChild ( "OptionsButton" ) as Button ;
246- _optionsFlyout = GetTemplateChild ( "OptionsFlyout" ) as MenuFlyout ;
247- _filterItemsMenuItem = GetTemplateChild ( "FilterItemsMenuItem" ) as MenuFlyoutItem ;
241+ _optionsFlyout = GetTemplateChild ( "OptionsFlyout" ) as TableViewFilterMenuFlyout ;
248242 _contentPresenter = GetTemplateChild ( "ContentPresenter" ) as ContentPresenter ;
249243 _v_gridLine = GetTemplateChild ( "VerticalGridLine" ) as Rectangle ;
250244
@@ -253,39 +247,16 @@ protected override void OnApplyTemplate()
253247 return ;
254248 }
255249
256- _optionsFlyout . Opening += OnOptionsFlyoutOpening ;
257- _optionsFlyout . Closed += OnOptionsFlyoutClosed ;
258- _optionsButton . Tapped += OnOptionsButtonTaped ;
259-
260- _filterItemsMenuItem ? . ApplyTemplate ( ) ;
261- _filterItemsControl = _filterItemsMenuItem ? . FindDescendant < TableViewFilterItemsControl > ( ) ;
262-
263- _filterItemsControl ? . TableView = _tableView ;
264- _filterItemsControl ? . ColumnHeader = this ;
250+ _optionsFlyout . TableView = _tableView ;
251+ _optionsFlyout . ColumnHeader = this ;
265252
266- _filterItemsMenuItem ? . PreviewKeyUp + = OnFilterItemsMenuItemPreviewKeyUp ;
253+ _optionsButton . Tapped += OnOptionsButtonTaped ;
267254
268255 SetOptionCommands ( ) ;
269256 SetFilterButtonVisibility ( ) ;
270257 EnsureGridLines ( ) ;
271258 }
272259
273- /// <summary>
274- /// Handles the Opening event for the options flyout.
275- /// </summary>
276- private async void OnOptionsFlyoutOpening ( object ? sender , object e )
277- {
278- _filterItemsControl ? . Initialize ( ) ;
279- }
280-
281- /// <summary>
282- /// Handles the Closed event for the options flyout.
283- /// </summary>
284- private void OnOptionsFlyoutClosed ( object ? sender , object e )
285- {
286- _filterItemsControl ? . ClearSearchBox ( ) ;
287- }
288-
289260 /// <summary>
290261 /// Handles the Tapped event for the options button.
291262 /// </summary>
@@ -294,14 +265,6 @@ private void OnOptionsButtonTaped(object sender, TappedRoutedEventArgs e)
294265 e . Handled = true ;
295266 }
296267
297- /// <summary>
298- /// Handles the PreviewKeyUp event for the filter items menu item.
299- /// </summary>
300- private void OnFilterItemsMenuItemPreviewKeyUp ( object sender , KeyRoutedEventArgs e )
301- {
302- e . Handled = e . Key is VirtualKey . Space ;
303- }
304-
305268 /// <summary>
306269 /// Handles changes to the SortDirection property.
307270 /// </summary>
@@ -565,4 +528,9 @@ internal void EnsureGridLines()
565528 /// Gets a value indicating whether the cursor is in the sizing area.
566529 /// </summary>
567530 private bool IsSizingCursor => ProtectedCursor is InputSystemCursor { CursorShape : InputSystemCursorShape . SizeWestEast } ;
531+
532+ /// <summary>
533+ /// Gets or sets the filter items control associated with the column header.
534+ /// </summary>
535+ internal TableViewFilterItemsControl ? FilterItemsControl { get ; set ; }
568536}
0 commit comments