Browse Source

Merge pull request #2976 from AvaloniaUI/fixes/stackpanel-layout

stackpanel copes with non-visible controls when arranging.
pull/2979/head
danwalmsley 7 years ago
committed by GitHub
parent
commit
4c557af078
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      src/Avalonia.Controls/Notifications/ReversibleStackPanel.cs
  2. 2
      src/Avalonia.Controls/StackPanel.cs
  3. 25
      tests/Avalonia.Controls.UnitTests/StackPanelTests.cs

5
src/Avalonia.Controls/Notifications/ReversibleStackPanel.cs

@ -39,6 +39,11 @@ namespace Avalonia.Controls
foreach (Control child in children)
{
if (!child.IsVisible)
{
continue;
}
double childWidth = child.DesiredSize.Width;
double childHeight = child.DesiredSize.Height;

2
src/Avalonia.Controls/StackPanel.cs

@ -251,7 +251,7 @@ namespace Avalonia.Controls
{
var child = children[i];
if (child == null)
if (child == null || !child.IsVisible)
{ continue; }
if (fHorizontal)

25
tests/Avalonia.Controls.UnitTests/StackPanelTests.cs

@ -332,6 +332,31 @@ namespace Avalonia.Controls.UnitTests
Assert.Equal(sizeWithTwoChildren, sizeWithThreeChildren);
}
[Theory]
[InlineData(Orientation.Horizontal)]
[InlineData(Orientation.Vertical)]
public void Only_Arrange_Visible_Children(Orientation orientation)
{
var hiddenPanel = new Panel { Width = 10, Height = 10, IsVisible = false };
var panel = new Panel { Width = 10, Height = 10 };
var target = new StackPanel
{
Spacing = 40,
Orientation = orientation,
Children =
{
hiddenPanel,
panel
}
};
target.Measure(Size.Infinity);
target.Arrange(new Rect(target.DesiredSize));
Assert.Equal(new Rect(0, 0, 10, 10), panel.Bounds);
}
private class TestControl : Control
{
public Size MeasureConstraint { get; private set; }

Loading…
Cancel
Save