diff --git a/samples/ControlCatalog/Pages/ScrollViewerPage.xaml b/samples/ControlCatalog/Pages/ScrollViewerPage.xaml index 1741c796db..fa8714959b 100644 --- a/samples/ControlCatalog/Pages/ScrollViewerPage.xaml +++ b/samples/ControlCatalog/Pages/ScrollViewerPage.xaml @@ -9,6 +9,7 @@ + @@ -24,6 +25,7 @@ diff --git a/samples/ControlCatalog/Pages/ScrollViewerPage.xaml.cs b/samples/ControlCatalog/Pages/ScrollViewerPage.xaml.cs index dcd7a88a56..a097f1f951 100644 --- a/samples/ControlCatalog/Pages/ScrollViewerPage.xaml.cs +++ b/samples/ControlCatalog/Pages/ScrollViewerPage.xaml.cs @@ -9,6 +9,7 @@ namespace ControlCatalog.Pages public class ScrollViewerPageViewModel : ViewModelBase { private bool _allowAutoHide; + private bool _enableInertia; private ScrollBarVisibility _horizontalScrollVisibility; private ScrollBarVisibility _verticalScrollVisibility; @@ -25,6 +26,7 @@ namespace ControlCatalog.Pages HorizontalScrollVisibility = ScrollBarVisibility.Auto; VerticalScrollVisibility = ScrollBarVisibility.Auto; AllowAutoHide = true; + EnableInertia = true; } public bool AllowAutoHide @@ -33,6 +35,12 @@ namespace ControlCatalog.Pages set => this.RaiseAndSetIfChanged(ref _allowAutoHide, value); } + public bool EnableInertia + { + get => _enableInertia; + set => this.RaiseAndSetIfChanged(ref _enableInertia, value); + } + public ScrollBarVisibility HorizontalScrollVisibility { get => _horizontalScrollVisibility; diff --git a/src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs b/src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs index 63ba869f1f..7c1ee13eed 100644 --- a/src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs +++ b/src/Avalonia.Base/Input/GestureRecognizers/ScrollGestureRecognizer.cs @@ -27,7 +27,8 @@ namespace Avalonia.Input.GestureRecognizers // Movement per second private Vector _inertia; private ulong? _lastMoveTimestamp; - + private bool _isScrollInertiaEnabled; + /// /// Defines the property. /// @@ -46,6 +47,15 @@ namespace Avalonia.Input.GestureRecognizers o => o.CanVerticallyScroll, (o, v) => o.CanVerticallyScroll = v); + /// + /// Defines the property. + /// + public static readonly DirectProperty IsScrollInertiaEnabledProperty = + AvaloniaProperty.RegisterDirect( + nameof(IsScrollInertiaEnabled), + o => o.IsScrollInertiaEnabled, + (o, v) => o.IsScrollInertiaEnabled = v); + /// /// Defines the property. /// @@ -72,6 +82,15 @@ namespace Avalonia.Input.GestureRecognizers get => _canVerticallyScroll; set => SetAndRaise(CanVerticallyScrollProperty, ref _canVerticallyScroll, value); } + + /// + /// Gets or sets whether the gesture should include inertia in it's behavior. + /// + public bool IsScrollInertiaEnabled + { + get => _isScrollInertiaEnabled; + set => SetAndRaise(IsScrollInertiaEnabledProperty, ref _isScrollInertiaEnabled, value); + } /// /// Gets or sets a value indicating the distance the pointer moves before scrolling is started @@ -169,7 +188,8 @@ namespace Avalonia.Input.GestureRecognizers if (_inertia == default || e.Timestamp == 0 || _lastMoveTimestamp == 0 - || e.Timestamp - _lastMoveTimestamp > 200) + || e.Timestamp - _lastMoveTimestamp > 200 + || !IsScrollInertiaEnabled) EndGesture(); else { diff --git a/src/Avalonia.Controls/ScrollViewer.cs b/src/Avalonia.Controls/ScrollViewer.cs index 1340de3af9..1c23919d0e 100644 --- a/src/Avalonia.Controls/ScrollViewer.cs +++ b/src/Avalonia.Controls/ScrollViewer.cs @@ -221,6 +221,14 @@ namespace Avalonia.Controls nameof(IsScrollChainingEnabled), defaultValue: true); + /// + /// Defines the property. + /// + public static readonly AttachedProperty IsScrollInertiaEnabledProperty = + AvaloniaProperty.RegisterAttached( + nameof(IsScrollInertiaEnabled), + defaultValue: true); + /// /// Defines the event. /// @@ -508,6 +516,15 @@ namespace Avalonia.Controls set => SetValue(IsScrollChainingEnabledProperty, value); } + /// + /// Gets or sets whether scroll gestures should include inertia in their behavior and value. + /// + public bool IsScrollInertiaEnabled + { + get => GetValue(IsScrollInertiaEnabledProperty); + set => SetValue(IsScrollInertiaEnabledProperty, value); + } + /// /// Scrolls the content up one line. /// diff --git a/src/Avalonia.Themes.Fluent/Controls/ScrollViewer.xaml b/src/Avalonia.Themes.Fluent/Controls/ScrollViewer.xaml index f13f775695..7a8c15bf60 100644 --- a/src/Avalonia.Themes.Fluent/Controls/ScrollViewer.xaml +++ b/src/Avalonia.Themes.Fluent/Controls/ScrollViewer.xaml @@ -43,7 +43,8 @@ IsScrollChainingEnabled="{TemplateBinding IsScrollChainingEnabled}"> + CanVerticallyScroll="{TemplateBinding CanVerticallyScroll}" + IsScrollInertiaEnabled="{TemplateBinding IsScrollInertiaEnabled}"/>