Skip to content

Commit

Permalink
DataGrid inertial scroll support (#13502) (#13511)
Browse files Browse the repository at this point in the history
  • Loading branch information
stogle authored Nov 6, 2023
1 parent c40b627 commit 90b09b1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
15 changes: 15 additions & 0 deletions src/Avalonia.Controls.DataGrid/DataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,21 @@ private void OnAreRowGroupHeadersFrozenChanged(AvaloniaPropertyChangedEventArgs
}
}

/// <summary>
/// Defines the <see cref="IsScrollInertiaEnabled"/> property.
/// </summary>
public static readonly AttachedProperty<bool> IsScrollInertiaEnabledProperty =
ScrollViewer.IsScrollInertiaEnabledProperty.AddOwner<DataGrid>();

/// <summary>
/// Gets or sets whether scroll gestures should include inertia in their behavior and value.
/// </summary>
public bool IsScrollInertiaEnabled
{
get => GetValue(IsScrollInertiaEnabledProperty);
set => SetValue(IsScrollInertiaEnabledProperty, value);
}

private bool _isValid = true;

public static readonly DirectProperty<DataGrid, bool> IsValidProperty =
Expand Down
8 changes: 6 additions & 2 deletions src/Avalonia.Controls.DataGrid/Themes/Fluent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,13 @@
<DataGridRowsPresenter Name="PART_RowsPresenter"
Grid.Row="1"
Grid.RowSpan="2"
Grid.ColumnSpan="3" Grid.Column="0">
Grid.ColumnSpan="3"
Grid.Column="0"
ScrollViewer.IsScrollInertiaEnabled="{TemplateBinding IsScrollInertiaEnabled}">
<DataGridRowsPresenter.GestureRecognizers>
<ScrollGestureRecognizer CanHorizontallyScroll="True" CanVerticallyScroll="True" />
<ScrollGestureRecognizer CanHorizontallyScroll="True"
CanVerticallyScroll="True"
IsScrollInertiaEnabled="{Binding (ScrollViewer.IsScrollInertiaEnabled), ElementName=PART_RowsPresenter}" />
</DataGridRowsPresenter.GestureRecognizers>
</DataGridRowsPresenter>
<Rectangle Name="PART_BottomRightCorner"
Expand Down
6 changes: 4 additions & 2 deletions src/Avalonia.Controls.DataGrid/Themes/Simple.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,12 @@

<DataGridRowsPresenter Name="PART_RowsPresenter"
Grid.Row="1"
Grid.ColumnSpan="2">
Grid.ColumnSpan="2"
ScrollViewer.IsScrollInertiaEnabled="{TemplateBinding IsScrollInertiaEnabled}">
<DataGridRowsPresenter.GestureRecognizers>
<ScrollGestureRecognizer CanHorizontallyScroll="True"
CanVerticallyScroll="True" />
CanVerticallyScroll="True"
IsScrollInertiaEnabled="{Binding (ScrollViewer.IsScrollInertiaEnabled), ElementName=PART_RowsPresenter}" />
</DataGridRowsPresenter.GestureRecognizers>
</DataGridRowsPresenter>
<Rectangle Name="PART_BottomRightCorner"
Expand Down

0 comments on commit 90b09b1

Please sign in to comment.