Skip to content

Commit

Permalink
Merge pull request #6340 from AvaloniaUI/bugfixes/fix-datagrid-scroll…
Browse files Browse the repository at this point in the history
…ing-on-trackpad

Fix DataGrid wheel scroll calculation
  • Loading branch information
jmacato authored Aug 1, 2021
2 parents 9dbcc98 + c285a0e commit 5024e70
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/Avalonia.Controls.DataGrid/DataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public partial class DataGrid : TemplatedControl
private const double DATAGRID_minimumColumnHeaderHeight = 4;
internal const double DATAGRID_maximumStarColumnWidth = 10000;
internal const double DATAGRID_minimumStarColumnWidth = 0.001;
private const double DATAGRID_mouseWheelDelta = 72.0;
private const double DATAGRID_mouseWheelDelta = 50.0;
private const double DATAGRID_maxHeadersThickness = 32768;

private const double DATAGRID_defaultRowHeight = 22;
Expand Down Expand Up @@ -2217,20 +2217,23 @@ protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
if (IsEnabled && !e.Handled && DisplayData.NumDisplayedScrollingElements > 0)
{
double scrollHeight = 0;
if (e.Delta.Y > 0)
var delta = DATAGRID_mouseWheelDelta * e.Delta.Y;
var deltaAbs = Math.Abs(delta);

if (delta > 0)
{
scrollHeight = Math.Max(-_verticalOffset, -DATAGRID_mouseWheelDelta);
scrollHeight = Math.Max(-_verticalOffset, -deltaAbs);
}
else if (e.Delta.Y < 0)
else if (delta < 0)
{
if (_vScrollBar != null && VerticalScrollBarVisibility == ScrollBarVisibility.Visible)
{
scrollHeight = Math.Min(Math.Max(0, _vScrollBar.Maximum - _verticalOffset), DATAGRID_mouseWheelDelta);
scrollHeight = Math.Min(Math.Max(0, _vScrollBar.Maximum - _verticalOffset), deltaAbs);
}
else
{
double maximum = EdgedRowsHeightCalculated - CellsHeight;
scrollHeight = Math.Min(Math.Max(0, maximum - _verticalOffset), DATAGRID_mouseWheelDelta);
scrollHeight = Math.Min(Math.Max(0, maximum - _verticalOffset), deltaAbs);
}
}
if (scrollHeight != 0)
Expand Down

0 comments on commit 5024e70

Please sign in to comment.