-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathTableViewColumnHeader.OptionComamnds.cs
More file actions
56 lines (46 loc) · 2.51 KB
/
Copy pathTableViewColumnHeader.OptionComamnds.cs
File metadata and controls
56 lines (46 loc) · 2.51 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
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using SD = WinUI.TableView.SortDirection;
namespace WinUI.TableView;
partial class TableViewColumnHeader
{
private bool _commandsInitialized;
private readonly StandardUICommand _sortAscendingCommand = new() { Label = TableViewLocalizedStrings.SortAscending };
private readonly StandardUICommand _sortDescendingCommand = new() { Label = TableViewLocalizedStrings.SortDescending };
private readonly StandardUICommand _clearSortingCommand = new() { Label = TableViewLocalizedStrings.ClearSorting };
private readonly StandardUICommand _clearFilterCommand = new() { Label = TableViewLocalizedStrings.ClearFilter };
/// <summary>
/// Sets commands to option menu items.
/// </summary>
private void SetOptionCommands()
{
InitializeCommands();
if (GetTemplateChild("SortAscendingMenuItem") is MenuFlyoutItem sortAscendingMenuItem)
sortAscendingMenuItem.Command = _sortAscendingCommand;
if (GetTemplateChild("SortDescendingMenuItem") is MenuFlyoutItem sortDescendingMenuItem)
sortDescendingMenuItem.Command = _sortDescendingCommand;
if (GetTemplateChild("ClearSortingMenuItem") is MenuFlyoutItem clearSortingMenuItem)
clearSortingMenuItem.Command = _clearSortingCommand;
if (GetTemplateChild("ClearFilterMenuItem") is MenuFlyoutItem clearFilterMenuItem)
clearFilterMenuItem.Command = _clearFilterCommand;
}
/// <summary>
/// Initializes the commands.
/// </summary>
private void InitializeCommands()
{
if (_commandsInitialized)
{
return;
}
_sortAscendingCommand.ExecuteRequested += delegate { DoSort(SD.Ascending); };
_sortAscendingCommand.CanExecuteRequested += (_, e) => e.CanExecute = CanSort && Column?.SortDirection != SD.Ascending;
_sortDescendingCommand.ExecuteRequested += delegate { DoSort(SD.Descending); };
_sortDescendingCommand.CanExecuteRequested += (_, e) => e.CanExecute = CanSort && Column?.SortDirection != SD.Descending;
_clearSortingCommand.ExecuteRequested += delegate { ClearSortingWithEvent(); };
_clearSortingCommand.CanExecuteRequested += (_, e) => e.CanExecute = Column?.SortDirection is not null;
_clearFilterCommand.ExecuteRequested += delegate { ClearFilter(); };
_clearFilterCommand.CanExecuteRequested += (_, e) => e.CanExecute = Column?.IsFiltered is true;
_commandsInitialized = true;
}
}