From 8bfbc100490b5ba5f0a7f803910c4b2e18040fd6 Mon Sep 17 00:00:00 2001 From: Joe Clapis Date: Sat, 8 Feb 2020 15:43:14 -0500 Subject: [PATCH] Added the ScrollToHome() and ScrollToEnd() methods to ScrollViewer. --- src/Avalonia.Controls/ScrollViewer.cs | 16 +++++++++++++ .../ScrollViewerTests.cs | 24 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/Avalonia.Controls/ScrollViewer.cs b/src/Avalonia.Controls/ScrollViewer.cs index 4fae867dbd..3d508d8b68 100644 --- a/src/Avalonia.Controls/ScrollViewer.cs +++ b/src/Avalonia.Controls/ScrollViewer.cs @@ -249,6 +249,22 @@ namespace Avalonia.Controls set { SetValue(VerticalScrollBarVisibilityProperty, value); } } + /// + /// Scrolls to the top-left corner of the content. + /// + public void ScrollToHome() + { + Offset = new Vector(double.NegativeInfinity, double.NegativeInfinity); + } + + /// + /// Scrolls to the bottom-left corner of the content. + /// + public void ScrollToEnd() + { + Offset = new Vector(double.NegativeInfinity, double.PositiveInfinity); + } + /// /// Gets a value indicating whether the viewer can scroll horizontally. /// diff --git a/tests/Avalonia.Controls.UnitTests/ScrollViewerTests.cs b/tests/Avalonia.Controls.UnitTests/ScrollViewerTests.cs index 2238175a4a..f281c83bb3 100644 --- a/tests/Avalonia.Controls.UnitTests/ScrollViewerTests.cs +++ b/tests/Avalonia.Controls.UnitTests/ScrollViewerTests.cs @@ -65,6 +65,30 @@ namespace Avalonia.Controls.UnitTests Assert.Equal(new Vector(10, 10), target.Offset); } + [Fact] + public void Test_ScrollToHome() + { + var target = new ScrollViewer(); + target.SetValue(ScrollViewer.ExtentProperty, new Size(50, 50)); + target.SetValue(ScrollViewer.ViewportProperty, new Size(10, 10)); + target.Offset = new Vector(25, 25); + target.ScrollToHome(); + + Assert.Equal(new Vector(0, 0), target.Offset); + } + + [Fact] + public void Test_ScrollToEnd() + { + var target = new ScrollViewer(); + target.SetValue(ScrollViewer.ExtentProperty, new Size(50, 50)); + target.SetValue(ScrollViewer.ViewportProperty, new Size(10, 10)); + target.Offset = new Vector(25, 25); + target.ScrollToEnd(); + + Assert.Equal(new Vector(0, 40), target.Offset); + } + private Control CreateTemplate(ScrollViewer control, INameScope scope) { return new Grid