From 341dcce179bf5f1e102d67dcfa107f8e1cfaa4cf Mon Sep 17 00:00:00 2001 From: Tim <47110241+timunie@users.noreply.github.com> Date: Wed, 6 Sep 2023 09:57:32 +0200 Subject: [PATCH] fix: DataGrid scroll should behave the same as ScrollViewer (#12787) if the user holds [Shift], we need to swap e.Delta (e.g. on Windows) if not already done by the OS (e.g. using Mac). --- src/Avalonia.Controls.DataGrid/DataGrid.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls.DataGrid/DataGrid.cs b/src/Avalonia.Controls.DataGrid/DataGrid.cs index de49d50637..311fb3de40 100644 --- a/src/Avalonia.Controls.DataGrid/DataGrid.cs +++ b/src/Avalonia.Controls.DataGrid/DataGrid.cs @@ -2285,7 +2285,16 @@ namespace Avalonia.Controls /// PointerWheelEventArgs protected override void OnPointerWheelChanged(PointerWheelEventArgs e) { - if(UpdateScroll(e.Delta * DATAGRID_mouseWheelDelta)) + var delta = e.Delta; + + // KeyModifiers.Shift should scroll in horizontal direction. This does not work on every platform. + // If Shift-Key is pressed and X is close to 0 we swap the Vector. + if (e.KeyModifiers == KeyModifiers.Shift && MathUtilities.IsZero(delta.X)) + { + delta = new Vector(delta.Y, delta.X); + } + + if(UpdateScroll(delta * DATAGRID_mouseWheelDelta)) { e.Handled = true; }