From 52606fa56d44818d5e68c3745b98a5ddd37cd41b Mon Sep 17 00:00:00 2001 From: Dariusz Komosinski Date: Sat, 20 Jun 2020 12:22:03 +0200 Subject: [PATCH] Implement auto hide and sync scrollviewer this scrollbar visibility. --- src/Avalonia.Controls/Primitives/ScrollBar.cs | 93 ++++++++++++++----- src/Avalonia.Controls/ScrollViewer.cs | 73 +++++++++++++++ .../Accents/FluentBaseDark.xaml | 2 +- src/Avalonia.Themes.Fluent/ScrollBar.xaml | 12 +-- src/Avalonia.Themes.Fluent/ScrollViewer.xaml | 21 ++++- 5 files changed, 167 insertions(+), 34 deletions(-) diff --git a/src/Avalonia.Controls/Primitives/ScrollBar.cs b/src/Avalonia.Controls/Primitives/ScrollBar.cs index e0431985af..42f8eb1137 100644 --- a/src/Avalonia.Controls/Primitives/ScrollBar.cs +++ b/src/Avalonia.Controls/Primitives/ScrollBar.cs @@ -41,11 +41,20 @@ namespace Avalonia.Controls.Primitives public static readonly StyledProperty OrientationProperty = AvaloniaProperty.Register(nameof(Orientation), Orientation.Vertical); + public static readonly StyledProperty AllowAutoHideProperty = + AvaloniaProperty.Register(nameof(AllowAutoHide), true); + + public static readonly DirectProperty IsExpandedProperty = + AvaloniaProperty.RegisterDirect( + nameof(IsExpanded), + o => o.IsExpanded); + private Button _lineUpButton; private Button _lineDownButton; private Button _pageUpButton; private Button _pageDownButton; - private DispatcherTimer _collapseTimer; + private DispatcherTimer _timer; + private bool _isExpanded; /// /// Initializes static members of the class. @@ -64,6 +73,18 @@ namespace Avalonia.Controls.Primitives UpdatePseudoClasses(Orientation); } + public bool IsExpanded + { + get => _isExpanded; + private set => SetAndRaise(IsExpandedProperty, ref _isExpanded, value); + } + + public bool AllowAutoHide + { + get { return GetValue(AllowAutoHideProperty); } + set { SetValue(AllowAutoHideProperty, value); } + } + /// /// Gets or sets the amount of the scrollable content that is currently visible. /// @@ -133,6 +154,10 @@ namespace Avalonia.Controls.Primitives { UpdatePseudoClasses(change.NewValue.GetValueOrDefault()); } + else if (change.Property == AllowAutoHideProperty) + { + UpdateIsExpandedState(); + } else { if (change.Property == MinimumProperty || @@ -149,16 +174,20 @@ namespace Avalonia.Controls.Primitives { base.OnPointerEnter(e); - ResetCollapseTimer(); - - Expand(); + if (AllowAutoHide) + { + ExpandAfterDelay(); + } } protected override void OnPointerLeave(PointerEventArgs e) { base.OnPointerLeave(e); - CollapseAfterDelay(); + if (AllowAutoHide) + { + CollapseAfterDelay(); + } } protected override void OnApplyTemplate(TemplateAppliedEventArgs e) @@ -188,8 +217,6 @@ namespace Avalonia.Controls.Primitives _pageUpButton = e.NameScope.Find