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