Browse Source

Added failing test for #1065.

Also add setter for `ScrollContentPresenter.CanScrollHorizontally`.
pull/1338/head
Steven Kirk 8 years ago
parent
commit
f22994a083
  1. 12
      src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs
  2. 26
      tests/Avalonia.Controls.UnitTests/Presenters/ScrollContentPresenterTests.cs

12
src/Avalonia.Controls/Presenters/ScrollContentPresenter.cs

@ -101,9 +101,13 @@ namespace Avalonia.Controls.Presenters
}
/// <summary>
/// Gets a value indicating whether the content can be scrolled horizontally.
/// Gets or sets a value indicating whether the content can be scrolled horizontally.
/// </summary>
public bool CanScrollHorizontally => GetValue(CanScrollHorizontallyProperty);
public bool CanScrollHorizontally
{
get => GetValue(CanScrollHorizontallyProperty);
set => SetValue(CanScrollHorizontallyProperty, value);
}
/// <summary>
/// Attempts to bring a portion of the target visual into view by scrolling the content.
@ -213,8 +217,8 @@ namespace Avalonia.Controls.Presenters
if (child != null)
{
var size = new Size(
Math.Max(finalSize.Width, child.DesiredSize.Width),
Math.Max(finalSize.Height, child.DesiredSize.Height));
Math.Max(finalSize.Width, child.DesiredSize.Width),
Math.Max(finalSize.Height, child.DesiredSize.Height));
child.Arrange(new Rect((Point)(-Offset), size));
return finalSize;
}

26
tests/Avalonia.Controls.UnitTests/Presenters/ScrollContentPresenterTests.cs

@ -201,6 +201,32 @@ namespace Avalonia.Controls.UnitTests.Presenters
Assert.Equal(new[] { "Viewport", "Extent" }, set);
}
[Fact]
public void Arrange_Should_Constrain_Child_Width_When_CanScrollHorizontally_False()
{
var child = new WrapPanel
{
Children =
{
new Border { Width = 40, Height = 50 },
new Border { Width = 40, Height = 50 },
new Border { Width = 40, Height = 50 },
}
};
var target = new ScrollContentPresenter
{
Content = child,
CanScrollHorizontally = false,
};
target.UpdateChild();
target.Measure(Size.Infinity);
target.Arrange(new Rect(0, 0, 100, 100));
Assert.Equal(100, child.Bounds.Width);
}
[Fact]
public void Setting_Offset_Should_Invalidate_Arrange()
{

Loading…
Cancel
Save