Browse Source

Merge pull request #3532 from jclapis/master

Added the ScrollToHome() and ScrollToEnd() methods to ScrollViewer.
pull/3546/head
Steven Kirk 6 years ago
committed by GitHub
parent
commit
1cc06a1a8a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      src/Avalonia.Controls/ScrollViewer.cs
  2. 24
      tests/Avalonia.Controls.UnitTests/ScrollViewerTests.cs

16
src/Avalonia.Controls/ScrollViewer.cs

@ -249,6 +249,22 @@ namespace Avalonia.Controls
set { SetValue(VerticalScrollBarVisibilityProperty, value); }
}
/// <summary>
/// Scrolls to the top-left corner of the content.
/// </summary>
public void ScrollToHome()
{
Offset = new Vector(double.NegativeInfinity, double.NegativeInfinity);
}
/// <summary>
/// Scrolls to the bottom-left corner of the content.
/// </summary>
public void ScrollToEnd()
{
Offset = new Vector(double.NegativeInfinity, double.PositiveInfinity);
}
/// <summary>
/// Gets a value indicating whether the viewer can scroll horizontally.
/// </summary>

24
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

Loading…
Cancel
Save