Skip to content

Commit 8ca1ce9

Browse files
AndrewKeepCodingArlodotexe
authored andcommitted
Add WrapPanel test for stretching last child into new row
1 parent 7f9a88c commit 8ca1ce9

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

components/Primitives/tests/Primitives.Tests.projitems

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
<Compile Include="$(MSBuildThisFileDirectory)WrapPanel\VerticalWrapPanelInsideParentWithLimitedHeight.xaml.cs">
5151
<DependentUpon>VerticalWrapPanelInsideParentWithLimitedHeight.xaml</DependentUpon>
5252
</Compile>
53+
<Compile Include="$(MSBuildThisFileDirectory)WrapPanel\WrapPanelStretchLastChildInNewRow.xaml.cs">
54+
<DependentUpon>WrapPanelStretchLastChildInNewRow.xaml</DependentUpon>
55+
</Compile>
5356
</ItemGroup>
5457
<ItemGroup>
5558
<Page Include="$(MSBuildThisFileDirectory)DockPanel\DockPanelSample.xaml">
@@ -76,6 +79,10 @@
7679
<SubType>Designer</SubType>
7780
<Generator>MSBuild:Compile</Generator>
7881
</Page>
82+
<Page Include="$(MSBuildThisFileDirectory)WrapPanel\WrapPanelStretchLastChildInNewRow.xaml">
83+
<SubType>Designer</SubType>
84+
<Generator>MSBuild:Compile</Generator>
85+
</Page>
7986
</ItemGroup>
8087
<ItemGroup>
8188
<Page Include="$(MSBuildThisFileDirectory)SwitchPresenter\SwitchConverterBrushSample.xaml">

components/Primitives/tests/Test_WrapPanel_StretchChild.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,30 @@ public void HorizontalWrapPanelInsideParentWithLimitedWidthTest(HorizontalWrapPa
101101
double lastChildExpectedWidth = wrapPanel.ActualWidth - precedingChildren.Sum(child => child.ActualWidth);
102102
Assert.AreEqual(lastChildExpectedWidth, lastChild.ActualWidth, "Last child width not as expected.");
103103
}
104+
105+
/// <summary>
106+
/// 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.
107+
/// </summary>
108+
/// <param name="page"></param>
109+
[TestCategory("WrapPanel")]
110+
[UIThreadTestMethod]
111+
public void WrapPanelStretchLastChildInNewRowTest(WrapPanelStretchLastChildInNewRow page)
112+
{
113+
var wrapPanel = page.FindDescendant<WrapPanel>();
114+
Assert.IsNotNull(wrapPanel, "Could not find WrapPanel.");
115+
Assert.IsFalse(wrapPanel.StretchChild is not StretchChild.Last, "WrapPanel StretchChild property not set to Last.");
116+
Assert.IsFalse(wrapPanel.Children.Count < 1, "No children to test.");
117+
118+
var precedingChildren = wrapPanel.Children.Cast<FrameworkElement>().Take(wrapPanel.Children.Count - 1);
119+
120+
foreach (var child in precedingChildren)
121+
{
122+
double expectedWidth = child.DesiredSize.Width;
123+
Assert.AreEqual(expectedWidth, child.ActualWidth, "Child width not as expected.");
124+
}
125+
126+
var lastChild = wrapPanel.Children.Cast<FrameworkElement>().Last();
127+
double lastChildExpectedWidth = wrapPanel.ActualWidth;
128+
Assert.AreEqual(lastChildExpectedWidth, lastChild.ActualWidth, "Last child width not as expected.");
129+
}
104130
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Page x:Class="PrimitivesTests.WrapPanelStretchLastChildInNewRow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:controls="using:CommunityToolkit.WinUI.Controls"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:local="using:PrimitivesTests.WrapPanel"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
9+
mc:Ignorable="d">
10+
11+
<Grid>
12+
<controls:WrapPanel Width="132"
13+
StretchChild="Last">
14+
<Rectangle Width="44"
15+
Height="44"
16+
Fill="Red" />
17+
<Rectangle Width="44"
18+
Height="44"
19+
Fill="Blue" />
20+
<Rectangle Width="44"
21+
Height="44"
22+
Fill="Green" />
23+
<Rectangle Height="44"
24+
Fill="Orange" />
25+
</controls:WrapPanel>
26+
</Grid>
27+
28+
</Page>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
namespace PrimitivesTests;
6+
7+
public sealed partial class WrapPanelStretchLastChildInNewRow : Page
8+
{
9+
public WrapPanelStretchLastChildInNewRow()
10+
{
11+
this.InitializeComponent();
12+
}
13+
}

0 commit comments

Comments
 (0)