Skip to content

Commit

Permalink
fix: DataGrid scroll should behave the same as ScrollViewer (#12787)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
timunie authored Sep 6, 2023
1 parent 93df05e commit 341dcce
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Avalonia.Controls.DataGrid/DataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2285,7 +2285,16 @@ protected virtual void OnLoadingRow(DataGridRowEventArgs e)
/// <param name="e">PointerWheelEventArgs</param>
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;
}
Expand Down

0 comments on commit 341dcce

Please sign in to comment.