Open garyhertel opened 2 years ago
How it works with ListBox, when it has context menu?
That might look like a ListBox, but it's actually a DataGrid with the headers not showing ;)
(it's not really useful showing the title Name everywhere for a single column DataGrid)
No, I mean how ListBox behaves in similar situation, when you have context menu AND it selects items on right click. Is it selects item while showing context menu? Or does context menu overrides selection behavior.
The ListBox seems to follow the same behavior as the DataGrid after the PR got added, where right clicking selects the item.
Anyways, if this isn't possible to add, I can probably work around it if this property was made public instead of internal:
DataGridCell.OwningColumn
I am not sure, but it feels like expected behavior for both DatsGrid and ListBox would be to ignore right click selection code if context menu is shown. I.e. set pointer event as handled after context menu was shown.
I think it kind of depends if you're going for simplicity (the new model), or a richer complex interface. Allowing right clicking without selecting expands your options to allow an additional "free" button since both left and right clicking don't update the DataGrid selection.
I wonder if that new Fluent cell selection rect should follow a right click though (maybe it breaks some assumptions, not sure what the right action is there). It might still be useful to have to target indicator for the right click?
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?
@sergevm you can try tunneling the event like explained here https://docs.avaloniaui.net/misc/wpf/tunnelling-events
Is 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
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:
https://github.com/garyhertel/Atlas