|
@@ -15,6 +15,7 @@ using Avalonia.Platform;
|
|
|
using Avalonia.Rendering;
|
|
|
using Avalonia.Rendering.Composition;
|
|
|
using Avalonia.UnitTests;
|
|
|
+using Avalonia.VisualTree;
|
|
|
using Moq;
|
|
|
using Xunit;
|
|
|
|
|
@@ -916,6 +917,82 @@ namespace Avalonia.Controls.UnitTests
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ [Theory]
|
|
|
+ [InlineData(1)]
|
|
|
+ [InlineData(2)]
|
|
|
+ [InlineData(3)]
|
|
|
+ public void MaxLines_Sets_ScrollViewer_MaxHeight(int maxLines)
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(Services))
|
|
|
+ {
|
|
|
+ var target = new TextBox
|
|
|
+ {
|
|
|
+ Template = CreateTemplate(),
|
|
|
+ MaxLines = maxLines,
|
|
|
+
|
|
|
+ // Define explicit whole number line height for predictable calculations
|
|
|
+ LineHeight = 20
|
|
|
+ };
|
|
|
+
|
|
|
+ var impl = CreateMockTopLevelImpl();
|
|
|
+ var topLevel = new TestTopLevel(impl.Object)
|
|
|
+ {
|
|
|
+ Template = CreateTopLevelTemplate(),
|
|
|
+ Content = target
|
|
|
+ };
|
|
|
+ topLevel.ApplyTemplate();
|
|
|
+ topLevel.LayoutManager.ExecuteInitialLayoutPass();
|
|
|
+
|
|
|
+ var textPresenter = target.FindDescendantOfType<TextPresenter>();
|
|
|
+ Assert.Equal("PART_TextPresenter", textPresenter.Name);
|
|
|
+ Assert.Equal(new Thickness(0), textPresenter.Margin); // Test assumes no margin on TextPresenter
|
|
|
+
|
|
|
+ var scrollViewer = target.FindDescendantOfType<ScrollViewer>();
|
|
|
+ Assert.Equal("PART_ScrollViewer", scrollViewer.Name);
|
|
|
+ Assert.Equal(maxLines * target.LineHeight, scrollViewer.MaxHeight);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [Theory]
|
|
|
+ [InlineData(1)]
|
|
|
+ [InlineData(2)]
|
|
|
+ [InlineData(3)]
|
|
|
+ public void MaxLines_Sets_ScrollViewer_MaxHeight_With_TextPresenter_Margin(int maxLines)
|
|
|
+ {
|
|
|
+ using (UnitTestApplication.Start(Services))
|
|
|
+ {
|
|
|
+ var target = new TextBox
|
|
|
+ {
|
|
|
+ Template = CreateTemplate(),
|
|
|
+ MaxLines = maxLines,
|
|
|
+
|
|
|
+ // Define explicit whole number line height for predictable calculations
|
|
|
+ LineHeight = 20
|
|
|
+ };
|
|
|
+
|
|
|
+ var impl = CreateMockTopLevelImpl();
|
|
|
+ var topLevel = new TestTopLevel(impl.Object)
|
|
|
+ {
|
|
|
+ Template = CreateTopLevelTemplate(),
|
|
|
+ Content = target
|
|
|
+ };
|
|
|
+ topLevel.ApplyTemplate();
|
|
|
+ topLevel.LayoutManager.ExecuteInitialLayoutPass();
|
|
|
+
|
|
|
+ var textPresenter = target.FindDescendantOfType<TextPresenter>();
|
|
|
+ Assert.Equal("PART_TextPresenter", textPresenter.Name);
|
|
|
+ var textPresenterMargin = new Thickness(horizontal: 0, vertical: 3);
|
|
|
+ textPresenter.Margin = textPresenterMargin;
|
|
|
+
|
|
|
+ target.InvalidateMeasure();
|
|
|
+ target.Measure(Size.Infinity);
|
|
|
+
|
|
|
+ var scrollViewer = target.FindDescendantOfType<ScrollViewer>();
|
|
|
+ Assert.Equal("PART_ScrollViewer", scrollViewer.Name);
|
|
|
+ Assert.Equal((maxLines * target.LineHeight) + textPresenterMargin.Top + textPresenterMargin.Bottom, scrollViewer.MaxHeight);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
[Fact]
|
|
|
public void CanUndo_CanRedo_Is_False_When_Initialized()
|
|
|
{
|
|
@@ -1125,7 +1202,7 @@ namespace Avalonia.Controls.UnitTests
|
|
|
return new FuncControlTemplate<TextBox>((control, scope) =>
|
|
|
new ScrollViewer
|
|
|
{
|
|
|
- Name = "Part_ScrollViewer",
|
|
|
+ Name = "PART_ScrollViewer",
|
|
|
Template = new FuncControlTemplate<ScrollViewer>(ScrollViewerTests.CreateTemplate),
|
|
|
Content = new TextPresenter
|
|
|
{
|