-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathTableViewFilterMenuFlyout.cs
More file actions
117 lines (99 loc) · 3.67 KB
/
Copy pathTableViewFilterMenuFlyout.cs
File metadata and controls
117 lines (99 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using System.Collections.Generic;
using System.Linq;
using WinUI.TableView.Controls;
using WinUI.TableView.Extensions;
namespace WinUI.TableView;
/// <summary>
/// Represents the filter menu flyout for a TableViewColumnHeader.
/// </summary>
public partial class TableViewFilterMenuFlyout : Flyout
{
private TableViewFilterItemsControl? _filterItemsControl;
private readonly StandardUICommand _okCommand = new() { Label = TableViewLocalizedStrings.Ok };
private readonly StandardUICommand _cancelCommand = new() { Label = TableViewLocalizedStrings.Cancel };
/// <summary>
/// Initializes a new instance of the <see cref="TableViewFilterMenuFlyout"/> class.
/// </summary>
public TableViewFilterMenuFlyout()
{
Items = [];
Opening += OnOpening;
Closed += OnClosed;
_okCommand.ExecuteRequested += delegate { ExecuteOkCommand(); };
_cancelCommand.ExecuteRequested += delegate { Hide(); };
}
/// <inheritdoc/>
protected override Control CreatePresenter()
{
var presenter = base.CreatePresenter();
presenter.Style = FlyoutPresenterStyle;
presenter.Loaded += OnPresenterLoaded;
return presenter;
}
/// <summary>
/// Handles the Opening event of the flyout, initializing the filter items control.
/// </summary>
private void OnOpening(object? sender, object e)
{
_filterItemsControl?.Initialize();
}
/// <summary>
/// Handles the Closed event of the flyout, clearing the search box in the filter items control.
/// </summary>
private void OnClosed(object? sender, object e)
{
_filterItemsControl?.ClearSearchBox();
}
/// <summary>
/// Handles the Loaded event of the MenuFlyoutPresenter.
/// </summary>
private void OnPresenterLoaded(object sender, RoutedEventArgs e)
{
var presenter = (FlyoutPresenter)sender;
var okButton = presenter.FindDescendant<Button>(b => b.Name is "OkButton");
var cancelButton = presenter.FindDescendant<Button>(b => b.Name is "CancelButton");
var menuPresenter = presenter.FindDescendant<MenuFlyoutPresenter>();
menuPresenter?.ItemsSource = Items;
_filterItemsControl = presenter.FindDescendant<TableViewFilterItemsControl>();
_filterItemsControl?.TableView = TableView;
_filterItemsControl?.ColumnHeader = ColumnHeader;
okButton?.Command = _okCommand;
cancelButton?.Command = _cancelCommand;
presenter.Loaded -= OnPresenterLoaded;
_filterItemsControl?.Initialize();
foreach (var item in Items.OfType<MenuFlyoutItem>())
{
item.Tapped += OnMenuItemTapped;
}
}
/// <summary>
/// Handles the Tapped event of menu items.
/// </summary>
private void OnMenuItemTapped(object sender, TappedRoutedEventArgs e)
{
Hide();
}
/// <summary>
/// Executes the OK command, applying the filter and hiding the flyout.
/// </summary>
private void ExecuteOkCommand()
{
Hide();
ColumnHeader?.ApplyFilter();
}
/// <summary>
/// Gets or sets the TableView associated with this filter menu flyout.
/// </summary>
public TableView? TableView { get; set; }
/// <summary>
/// Gets or sets the TableViewColumnHeader associated with this filter menu flyout.
/// </summary>
public TableViewColumnHeader? ColumnHeader { get; set; }
/// <summary>
/// Gets or sets the collection of menu items to be displayed in the filter flyout.
/// </summary>
public IList<MenuFlyoutItemBase> Items { get; set; }
}