You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The DataGridColumnHeader's ProcessSort method's default handling is using keyboard modifers (shift) to determine if it needs to do multi sort or not. However it doesn't forward the keyboard modifiers to the event handler. So in a user defined sort handler it is effectively impossible to replicate similar behaviour to the default handler. I have quoted the relevant datagrid source code below.
Since the Input manager and Keyboard Device seems to be internal I can't seem to do something like GetAsyncKeyState in windows API. I can't find an easy workaround for this either.
Basically if one would need the modifiers in a non-input event and the modifiers are not forwarded we are out of luck.
A potential solution for this one case is to include modifiers in DataGridColumnEventArgs.
{
// if we can sort:
// - AllowUserToSortColumns and CanSort are true, and
// - OwningColumn is bound
// then try to sort
if (OwningColumn != null
&& OwningGrid != null
&& OwningGrid.EditingRow == null
&& OwningColumn != OwningGrid.ColumnsInternal.FillerColumn
&& OwningGrid.CanUserSortColumns
&& OwningColumn.CanUserSort)
{
var ea = new DataGridColumnEventArgs(OwningColumn);
OwningGrid.OnColumnSorting(ea);
if (!ea.Handled && OwningGrid.DataConnection.AllowSort && OwningGrid.DataConnection.SortDescriptions != null)
{
// - DataConnection.AllowSort is true, and
// - SortDescriptionsCollection exists, and
// - the column's data type is comparable
DataGrid owningGrid = OwningGrid;
DataGridSortDescription newSort;
KeyboardHelper.GetMetaKeyState(this, keyModifiers, out bool ctrl, out bool shift);
Thanks in advance!
To Reproduce
Try to access the shift key state from a custom sort handler and implement multi-sort. <DataGrid Sorting="Example_Sorting">
Expected behavior
Keyboard modifiers are accessible in the Sort event.
Avalonia version
11.2.3
OS
No response
Additional context
No response
The text was updated successfully, but these errors were encountered:
I have an ad hoc fix locally that adds an extra modifier property to DataGridColumnEventArgs. That seems to work without breaking compatibility. There are places where the modifer is not accessible or relevant when using this argument type, in this case it is set to None.
But I also understand if you'd rather spin off a more specific event arg type specific to sort instead although it'd really break compatibility.
If you think this works without breaking, feel free to provide a PR for a review / API discussion. Maybe adding a property to an existing event arg is allowed.
Describe the bug
The DataGridColumnHeader's ProcessSort method's default handling is using keyboard modifers (shift) to determine if it needs to do multi sort or not. However it doesn't forward the keyboard modifiers to the event handler. So in a user defined sort handler it is effectively impossible to replicate similar behaviour to the default handler. I have quoted the relevant datagrid source code below.
A potential solution for this one case is to include modifiers in DataGridColumnEventArgs.
Thanks in advance!
To Reproduce
Try to access the shift key state from a custom sort handler and implement multi-sort.
<DataGrid Sorting="Example_Sorting">
Expected behavior
Keyboard modifiers are accessible in the Sort event.
Avalonia version
11.2.3
OS
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: