Add ListView-like hotkeys support to TableView #251
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, andGetRowFromElementto manage row selection and focus. Updatedusingdirectives to includeMicrosoft.UI.Xaml.Mediafor 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.