Add option to configure DataGrid Right Click Row Selection Behavior
See original GitHub issueIs your feature request related to a problem? Please describe.
A recent PR caused a regression in behavior for the DataGrid Right Click Context Menu:
https://github.com/AvaloniaUI/Avalonia/pull/6394
This PR changed the DataGrid Right click behavior to select the item beneath the mouse, instead of retaining the existing DataGrid selections.
At least for my framework and app that uses it, this fix isn’t a desirable behavior and caused a regression. Although I can see why it might be desirable for many apps.
For my app the DataGrid ContextMenu has the following options:
Copy - Cell Contents Copy - Column Copy - Row Copy - Selected Copy - DataGrid
Users will frequently right click on an unselected cell to copy it’s contents. These cells aren’t always selected since users might want to copy a description value in something like a property inspector.
Additionally, in my app the DataGrid selections create controls based on the selections, which can in turn create their own controls. So retaining the existing selections is really important. Otherwise a lot of extra sub-controls get updated which is distracting, takes extra loading time, and users then often have to reselect their previous selections. And multi-selecting makes this problem even worse, since it also reselects a single row if the target is different from one of the currently selected rows.
Describe the solution you’d like A clear and concise description of what you want to happen.
Can you add an option for controlling the DataGrid right click selection behavior so both options are possible? Specifically, there should be the following options for the DataGrid
- Right Clicking updates selection to target (new behavior with that fix)
- Right Clicking doesn’t update the selection to the target (previous behavior before the fix)
Specifically for the DataGridCell.DataGridCell_PointerPressed()
Describe alternatives you’ve considered A clear and concise description of any alternative solutions or features you’ve considered.
The PR that added the fix modified the DataGridCell_PointerPressed() to update the selection when right clicking. I could try overriding that event handler, but that function still needs to be called to get the Column from the DataGridCellPointerPressedEventArgs it generates. And the Column is needed for the Copy - Column
shortcut in the Content Menu. I’m unaware of any other way to get the column, since the DataGridCell.OwningColumn is internal.
It would be really helpful if the following were public too:
DataGridCell.OwningColumn DataGridCell.OwningGrid DataGridRow.OwningGrid
(The OwningGrid currently requires searching up the Parent controls tree to determine the DataGrid)
Additional context Add any other context or screenshots about the feature request here.
Here’s a screenshot of the test app (the primary app is internal), but I’m hoping to get the framework out soon:
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (7 by maintainers)
Top GitHub Comments
@sergevm you can try tunneling the event like explained here https://docs.avaloniaui.net/misc/wpf/tunnelling-events
Interesting … if there is an expensive action behind row selection, it would be nice if you could indeed prevent the row selection from happening on right click. Running into the performance impact myself actually, and in my context, still had some code that listens on pointer pressed, to select the row from code (the code was written before the aforementioned PR). Is there an alternative in the mean time, similar to Preview[EVENT] etc?