From 0dd127c2a5bb72d365e480e28db2fdaabe99e0a3 Mon Sep 17 00:00:00 2001 From: Compunet <117437050+dme-compunet@users.noreply.github.com> Date: Thu, 29 Jan 2026 12:16:06 +0200 Subject: [PATCH] Prevent ScrollBar collapsing during active thumb drag --- src/Avalonia.Controls/Primitives/ScrollBar.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Avalonia.Controls/Primitives/ScrollBar.cs b/src/Avalonia.Controls/Primitives/ScrollBar.cs index 7df7012f8f..89dcb9a8d4 100644 --- a/src/Avalonia.Controls/Primitives/ScrollBar.cs +++ b/src/Avalonia.Controls/Primitives/ScrollBar.cs @@ -85,6 +85,7 @@ namespace Avalonia.Controls.Primitives private bool _isExpanded; private CompositeDisposable? _ownerSubscriptions; private ScrollViewer? _owner; + private bool _isDragging; /// /// Initializes static members of the class. @@ -92,6 +93,7 @@ namespace Avalonia.Controls.Primitives static ScrollBar() { Thumb.DragDeltaEvent.AddClassHandler((x, e) => x.OnThumbDragDelta(e), RoutingStrategies.Bubble); + Thumb.DragStartedEvent.AddClassHandler((x, e) => x.OnThumbDragStart(e), RoutingStrategies.Bubble); Thumb.DragCompletedEvent.AddClassHandler((x, e) => x.OnThumbDragComplete(e), RoutingStrategies.Bubble); FocusableProperty.OverrideMetadata(new(false)); @@ -325,7 +327,7 @@ namespace Avalonia.Controls.Primitives { base.OnPointerExited(e); - if (AllowAutoHide) + if (AllowAutoHide && !_isDragging) { CollapseAfterDelay(); } @@ -491,8 +493,21 @@ namespace Avalonia.Controls.Primitives { OnScroll(ScrollEventType.ThumbTrack); } + + private void OnThumbDragStart(VectorEventArgs e) + { + _isDragging = true; + } + private void OnThumbDragComplete(VectorEventArgs e) { + _isDragging = false; + + if (AllowAutoHide && !IsPointerOver) + { + CollapseAfterDelay(); + } + OnScroll(ScrollEventType.EndScroll); }