Skip to content

Commit

Permalink
fix(scrollviewer): Add ShouldFallBackToNativeScrollBars flag
Browse files Browse the repository at this point in the history
When set to False on ScrollViewer as an attached property, this will prevent native scrollbars showing when no ScrollBar is found in the ControlTemplate. Defaults to true, for compatibility with older versions of the default style and platforms where ScrollBar is not yet fully supported.
  • Loading branch information
davidjohnoliver committed Feb 3, 2021
1 parent e87a198 commit 6964f22
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions src/Uno.UI/UI/Xaml/Controls/ScrollViewer/ScrollViewer.Uno.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,32 @@ public static void SetUpdatesMode(Windows.UI.Xaml.Controls.ScrollViewer scrollVi
/// <returns>The updates mode of the <paramref name="scrollViewer"/>.</returns>
public static ScrollViewerUpdatesMode GetUpdatesMode(Windows.UI.Xaml.Controls.ScrollViewer scrollViewer)
=> (ScrollViewerUpdatesMode)scrollViewer.GetValue(UpdatesModeProperty);

/// <summary>
/// Getter for ShouldFallBackToNativeScrollBars attached property. If true, and no <see cref="Windows.UI.Xaml.Primitives.ScrollBar"/> is
/// found in <paramref name="scrollViewer"/>'s template, then native scroll bars (for platforms where available) will be shown instead.
/// If false, no scroll bars will be shown. True by default, for backward-compatibility.
/// </summary>
/// <param name="scrollViewer"></param>
/// <returns></returns>
public static bool GetShouldFallBackToNativeScrollBars(Windows.UI.Xaml.Controls.ScrollViewer scrollViewer)
{
return (bool)scrollViewer.GetValue(ShouldFallBackToNativeScrollBarsProperty);
}

/// <summary>
/// Setter for ShouldFallBackToNativeScrollBars attached property. If true, and no <see cref="Windows.UI.Xaml.Primitives.ScrollBar"/> is
/// found in <paramref name="scrollViewer"/>'s template, then native scroll bars (for platforms where available) will be shown instead.
/// If false, no scroll bars will be shown. True by default, for backward-compatibility.
/// </summary>
public static void SetShouldFallBackToNativeScrollBars(Windows.UI.Xaml.Controls.ScrollViewer scrollViewer, bool value)
{
scrollViewer.SetValue(ShouldFallBackToNativeScrollBarsProperty, value);
}

public static readonly DependencyProperty ShouldFallBackToNativeScrollBarsProperty =
DependencyProperty.RegisterAttached("ShouldFallBackToNativeScrollBars", typeof(bool), typeof(ScrollViewer), new PropertyMetadata(true));


}
}
4 changes: 2 additions & 2 deletions src/Uno.UI/UI/Xaml/Controls/ScrollViewer/ScrollViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -774,11 +774,11 @@ private static bool ComputeIsScrollEnabled(double scrollable, ScrollBarVisibilit
&& visibility != ScrollBarVisibility.Disabled
&& mode != ScrollMode.Disabled;

private static ScrollBarVisibility ComputeNativeScrollBarVisibility(ScrollBarVisibility visibility, ScrollMode mode, ScrollBar? managedScrollbar)
private ScrollBarVisibility ComputeNativeScrollBarVisibility(ScrollBarVisibility visibility, ScrollMode mode, ScrollBar? managedScrollbar)
=> mode switch
{
ScrollMode.Disabled => ScrollBarVisibility.Disabled,
_ when managedScrollbar is null => visibility,
_ when managedScrollbar is null && Uno.UI.Xaml.Controls.ScrollViewer.GetShouldFallBackToNativeScrollBars(this) => visibility,
_ when visibility == ScrollBarVisibility.Disabled => ScrollBarVisibility.Disabled,
_ => ScrollBarVisibility.Hidden // If a managed scroll bar was set in the template, native scroll bar has to stay Hidden
};
Expand Down

0 comments on commit 6964f22

Please sign in to comment.