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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
40 additions and
0 deletions
-
src/Avalonia.Controls/ScrollViewer.cs
-
tests/Avalonia.Controls.UnitTests/ScrollViewerTests.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>
|
|
|
|
|
|
|
|
@ -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 |
|
|
|
|