Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/docs/accessibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ Uses `AutomationProperties.Name` if set on the `TableViewRowHeader`, otherwise d
| **Ctrl+Shift+A** | Deselect all |
| **Ctrl+C** | Copy to clipboard |

The column header row is one tab stop: **Tab** to it, then move between headers with the **Left** / **Right** arrow keys.

| Key (on a column header) | Action |
|---|---|
| **Enter** / **Space** | Sort by the column (cycles like a click); **Ctrl** adds to the existing sort, like **Ctrl**+click |
| **Alt+Down**, **Shift+F10** or the **Menu** key | Open the column's options (sort, group, filter) |

## Screen reader behavior

When navigating with a screen reader such as Narrator:
Expand Down
47 changes: 47 additions & 0 deletions src/TableViewColumnHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public TableViewColumnHeader()
ManipulationMode = ManipulationModes.TranslateX;
RegisterPropertyChangedCallback(WidthProperty, OnWidthChanged);
RightTapped += OnRightTapped;
ContextRequested += OnContextRequested;
}

/// <summary>
Expand Down Expand Up @@ -312,6 +313,52 @@ internal void HideFlyout()
_optionsFlyout?.Hide();
}

/// <summary>
/// Keyboard access to what a click does: Enter or Space sorts (Ctrl adds to the existing sort, as Ctrl+click does),
/// and Alt+Down opens the column's options. Shift+F10 and the Menu key open them too (see OnContextRequested).
/// </summary>
protected override void OnKeyDown(KeyRoutedEventArgs e)
{
if (e.Key is VirtualKey.Enter or VirtualKey.Space && CanSort && Column is not null)
{
DoSort(GetNextSortDirection(), !IsKeyDown(VirtualKey.Control));
e.Handled = true;
}
else if (e.Key is VirtualKey.Down && IsKeyDown(VirtualKey.Menu) && ShowOptions())
{
e.Handled = true;
}

base.OnKeyDown(e);
}

/// <summary>
/// Opens the column's options for a keyboard context request (Shift+F10, the Menu key). A right-click also
/// raises this, with a pointer position; those keep going through <see cref="TableView.UseRightClickForColumnFilter"/>.
/// </summary>
private void OnContextRequested(UIElement sender, ContextRequestedEventArgs e)
{
if (!e.TryGetPosition(this, out _) && ShowOptions())
{
e.Handled = true;
}
}

/// <summary>Opens the options flyout (sort, group, filter), if the column has one.</summary>
private bool ShowOptions()
{
if (_optionsButton?.Flyout is not { } flyout || !CanFilter)
{
return false;
}

flyout.ShowAt(_optionsButton);
return true;
}

private static bool IsKeyDown(VirtualKey key) =>
InputKeyboardSource.GetKeyStateForCurrentThread(key).HasFlag(CoreVirtualKeyStates.Down);

/// <inheritdoc/>
protected override void OnTapped(TappedRoutedEventArgs e)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Themes/TableViewColumnHeader.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<Setter Property="HorizontalContentAlignment"
Value="Stretch" />
<Setter Property="IsTabStop"
Value="False" />
Value="True" />
<Setter Property="Background">
<Setter.Value>
<SolidColorBrush Opacity="0" />
Expand Down
2 changes: 2 additions & 0 deletions src/Themes/TableViewHeaderRow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
<Setter.Value>
<ControlTemplate TargetType="local:TableViewHeaderRow">
<Grid x:Name="root"
TabFocusNavigation="Once"
win:XYFocusKeyboardNavigation="Enabled"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
Expand Down