Skip to content
Open
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
2 changes: 1 addition & 1 deletion components/Primitives/src/WrapPanel/WrapPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void Arrange(UIElement child, bool isLast = false)
}

var desiredMeasure = new UvMeasure(Orientation, child.DesiredSize);
if ((desiredMeasure.U + position.U + paddingEnd.U) > parentMeasure.U)
if ((desiredMeasure.U + position.U + paddingEnd.U) > parentMeasure.U || position.U >= parentMeasure.U)
{
// next row!
position.U = paddingStart.U;
Expand Down
7 changes: 7 additions & 0 deletions components/Primitives/tests/Primitives.Tests.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
<Compile Include="$(MSBuildThisFileDirectory)WrapPanel\VerticalWrapPanelInsideParentWithLimitedHeight.xaml.cs">
<DependentUpon>VerticalWrapPanelInsideParentWithLimitedHeight.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)WrapPanel\WrapPanelStretchLastChildInNewRow.xaml.cs">
<DependentUpon>WrapPanelStretchLastChildInNewRow.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Include="$(MSBuildThisFileDirectory)DockPanel\DockPanelSample.xaml">
Expand All @@ -76,6 +79,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)WrapPanel\WrapPanelStretchLastChildInNewRow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Include="$(MSBuildThisFileDirectory)SwitchPresenter\SwitchConverterBrushSample.xaml">
Expand Down
26 changes: 26 additions & 0 deletions components/Primitives/tests/Test_WrapPanel_StretchChild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,30 @@ public void HorizontalWrapPanelInsideParentWithLimitedWidthTest(HorizontalWrapPa
double lastChildExpectedWidth = wrapPanel.ActualWidth - precedingChildren.Sum(child => child.ActualWidth);
Assert.AreEqual(lastChildExpectedWidth, lastChild.ActualWidth, "Last child width not as expected.");
}

/// <summary>
/// When a WrapPanel's width is constrained such that the last child wraps to a new row, the last child with Stretch alignment should fill the entire width of the new row.
/// </summary>
/// <param name="page"></param>
[TestCategory("WrapPanel")]
[UIThreadTestMethod]
public void WrapPanelStretchLastChildInNewRowTest(WrapPanelStretchLastChildInNewRow page)
{
var wrapPanel = page.FindDescendant<WrapPanel>();
Assert.IsNotNull(wrapPanel, "Could not find WrapPanel.");
Assert.IsFalse(wrapPanel.StretchChild is not StretchChild.Last, "WrapPanel StretchChild property not set to Last.");
Assert.IsFalse(wrapPanel.Children.Count < 1, "No children to test.");

var precedingChildren = wrapPanel.Children.Cast<FrameworkElement>().Take(wrapPanel.Children.Count - 1);

foreach (var child in precedingChildren)
{
double expectedWidth = child.DesiredSize.Width;
Assert.AreEqual(expectedWidth, child.ActualWidth, "Child width not as expected.");
}

var lastChild = wrapPanel.Children.Cast<FrameworkElement>().Last();
double lastChildExpectedWidth = wrapPanel.ActualWidth;
Assert.AreEqual(lastChildExpectedWidth, lastChild.ActualWidth, "Last child width not as expected.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Page x:Class="PrimitivesTests.WrapPanelStretchLastChildInNewRow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:PrimitivesTests.WrapPanel"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<Grid>
<controls:WrapPanel Width="132"
StretchChild="Last">
<Rectangle Width="44"
Height="44"
Fill="Red" />
<Rectangle Width="44"
Height="44"
Fill="Blue" />
<Rectangle Width="44"
Height="44"
Fill="Green" />
<Rectangle Height="44"
Fill="Orange" />
</controls:WrapPanel>
</Grid>

</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace PrimitivesTests;

public sealed partial class WrapPanelStretchLastChildInNewRow : Page
{
public WrapPanelStretchLastChildInNewRow()
{
this.InitializeComponent();
}
}
Loading