Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGrid should support inertial scrolling #13502

Closed
stogle opened this issue Nov 6, 2023 · 3 comments · Fixed by #13511
Closed

DataGrid should support inertial scrolling #13502

stogle opened this issue Nov 6, 2023 · 3 comments · Fixed by #13511
Assignees
Labels
area-datagrid enhancement help-wanted A contribution from the community would be most welcome.

Comments

@stogle
Copy link
Contributor

stogle commented Nov 6, 2023

Is your feature request related to a problem? Please describe.

DataGrid does not support inertial scrolling when using touch gestures to scroll, unlike other controls that use ScrollViewer internally. This makes it harder to use on touch-enabled devices.

Describe the solution you'd like

DataGrid should have an IsScrollInertiaEnabled property, just like ScrollViewer does, that is true by default.

Describe alternatives you've considered

I'm able to enable inertial scrolling by adding a TemplateApplied event handler to the DataGrid, finding its DataGridRowPresenter, finding that object's ScrollGestureRecognizer, and setting IsScrollInertiaEnabled to true, but it is convoluted and needs to be done for every DataGrid in my application. Perhaps there is an easier way?

Additional context

I think this can be implemented the same way it is done in ScrollViewer, by adding a property to DataGrid.cs:

        /// <summary>
        /// Defines the <see cref="IsScrollInertiaEnabled"/> property.
        /// </summary>
        public static readonly AttachedProperty<bool> IsScrollInertiaEnabledProperty =
            AvaloniaProperty.RegisterAttached<ScrollViewer, Control, bool>(
                nameof(IsScrollInertiaEnabled),
                defaultValue: true);

        /// <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);
        }

then changing the Fluent and Simple templates to use it:

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

If this is the right approach I would be happy to submit a pull request.

@maxkatz6
Copy link
Member

maxkatz6 commented Nov 6, 2023

Yes, previously there wasn't IsScrollInertiaEnabled property, and inertia was enabled always with touch input.
It seems DataGrid was missed when IsScrollInertiaEnabled property was added.

Your proposal changes make sense. Except, you can try to create a property definition with AddOwner:

        public static readonly AttachedProperty<bool> IsScrollInertiaEnabledProperty =
            ScrollViewer.IsScrollInertiaEnabledProperty.AddOwner<DataGrid>();

@timunie timunie added the help-wanted A contribution from the community would be most welcome. label Nov 6, 2023
@timunie
Copy link
Contributor

timunie commented Nov 6, 2023

@stogle I assigned you as you mentioned you want to contribute. If that changes, let me know. Your help is welcome ❤️

stogle added a commit to stogle/Avalonia that referenced this issue Nov 6, 2023
@stogle
Copy link
Contributor Author

stogle commented Nov 6, 2023

@stogle I assigned you as you mentioned you want to contribute. If that changes, let me know. Your help is welcome ❤️

Thanks @timunie, I created #13511 and the checks passed but it didn't give me a link to a package I can use for testing?

Edit: found the package 11.1.999-cibuild0041588-beta on https://nuget-feed-all.avaloniaui.net/v3/index.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-datagrid enhancement help-wanted A contribution from the community would be most welcome.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants