Skip to content

Conversation

@AlexanderBlackman
Copy link
Contributor

Not sure if this is fixing a bug or adding feature so I've added a property, UseListViewHotkeys that makes TableView in SelectionMode="Multiple" use ListView hotkeys. It defaults to false, so there won't be any backwards compatibility issues.

In the default WinUI 3 ListView, when SelectionMode="Multiple,
The 'Up' and 'Down' keys move the selection border
'Enter' toggles selection.
'Shift'+'Up'/'Down' when moving from a SelectedItem selects the destination item without deselecting other items anywhere.
The new property causes TableView to be like this, whilst still maintaining "tab" to edit next cell, 'enter' to edit the below cell and all other hotkeys.
If set to false... it keeps the original behaviour.

In TableView, when SelectionMode="Multiple" and SelectionUnit is "Row".
(or the checkbox column if "RowOrColumn")

'Up' selects the destination item and keeps anything below it selected, deselecting all consequentive rows above it. (non-consequentive items stay selected
'Down' does the reverse.
'Left'/'Right' deselects all consequentive items but the current cell.
'Enter' behaves super weirdly, if the checkbox cell is highlighted, it selects the second row and moves the selection border to the second row whilst keeping the prior item selected. Otherwise it behaves like the 'Down' key.
'Shift' key has no effect. (I've checked TableView.SelectRows() so I'm surprised)
I also had a look at SelectionMode="Extended" but TableView/ListView behave the same.

Added helper methods ToggleCurrentRowSelection,
GetFocusedRowIndex, and GetRowFromElement to manage row selection and focus. Updated using directives to include Microsoft.UI.Xaml.Media for visual tree traversal.

I did not change the VirtualKey.Left in the selection checkbox column, selecting the row. I'm assuming this is intended behaviour.

hephaestusdailylog@gmail.com and others added 3 commits November 21, 2025 11:06
Introduced a new `UseListViewHotkeys` dependency property to the
`TableView` class, allowing users to enable ListView-like hotkeys
for navigation and selection. This feature is opt-in and defaults
to `false` to ensure backward compatibility.

Enhanced the `OnKeyDown` method to support additional keyboard
navigation and selection scenarios when `UseListViewHotkeys` is
enabled. Added support for toggling row selection with `Enter`
and improved navigation using keys like `Up`, `Down`, `Home`,
`End`, `PageUp`, and `PageDown`.

Added helper methods `ToggleCurrentRowSelection`,
`GetFocusedRowIndex`, and `GetRowFromElement` to manage row
selection and focus. Updated `using` directives to include
`Microsoft.UI.Xaml.Media` for visual tree traversal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant