Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DockPanel index out of range #18261

Merged
merged 2 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Avalonia.Controls/DockPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ protected override Size MeasureOverride(Size availableSize)
}
}

if (LastChildFill)
if (LastChildFill && Children.Count > 0)
{
var child = Children[Children.Count - 1];
var childConstraint = new Size(
Expand Down Expand Up @@ -265,7 +265,7 @@ protected override Size ArrangeOverride(Size finalSize)
}
}

if (LastChildFill)
if (LastChildFill && Children.Count > 0)
{
var child = Children[Children.Count - 1];
child.Arrange(new Rect(currentBounds.X, currentBounds.Y, currentBounds.Width, currentBounds.Height));
Expand Down
15 changes: 15 additions & 0 deletions tests/Avalonia.Controls.UnitTests/DockPanelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ namespace Avalonia.Controls.UnitTests
{
public class DockPanelTests
{
[Fact]
public void DockPanel_Without_Child()
{
var target = new DockPanel
{
Width = 10,
Height = 10
};

target.Measure(Size.Infinity);
target.Arrange(new Rect(target.DesiredSize));

Assert.Equal(new Rect(0, 0, 10, 10), target.Bounds);
}

[Fact]
public void Should_Dock_Controls_Horizontal_First()
{
Expand Down