diff --git a/components/Primitives/src/WrapPanel/WrapPanel.cs b/components/Primitives/src/WrapPanel/WrapPanel.cs
index 58561458..532161a7 100644
--- a/components/Primitives/src/WrapPanel/WrapPanel.cs
+++ b/components/Primitives/src/WrapPanel/WrapPanel.cs
@@ -219,7 +219,8 @@ void Arrange(UIElement child, bool isLast = false)
}
// Stretch the last item to fill the available space
- if (isLast)
+ // if the parent measure is not infinite
+ if (isLast && double.IsInfinity(parentMeasure.U) is false)
{
desiredMeasure.U = parentMeasure.U - position.U;
}
diff --git a/components/Primitives/tests/Primitives.Tests.projitems b/components/Primitives/tests/Primitives.Tests.projitems
index 39e21d6d..79523a18 100644
--- a/components/Primitives/tests/Primitives.Tests.projitems
+++ b/components/Primitives/tests/Primitives.Tests.projitems
@@ -33,10 +33,14 @@
+
AutoLayoutFixedElementZeroZeroSpecialPage.xaml
+
+ WrapPanelSample.xaml
+
@@ -47,6 +51,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
diff --git a/components/Primitives/tests/Test_WrapPanel_Infinity.cs b/components/Primitives/tests/Test_WrapPanel_Infinity.cs
new file mode 100644
index 00000000..416c1ba1
--- /dev/null
+++ b/components/Primitives/tests/Test_WrapPanel_Infinity.cs
@@ -0,0 +1,48 @@
+// 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.
+
+using CommunityToolkit.Tests;
+using CommunityToolkit.WinUI.Controls;
+
+namespace PrimitivesTests;
+
+[TestClass]
+public class Test_WrapPanel_Infinity : VisualUITestBase
+{
+ [TestCategory("WrapPanel")]
+ [TestMethod]
+ public async Task Test_WrapPanel_InfinityWidth_WithStretchChild_Last()
+ {
+ await App.DispatcherQueue.EnqueueAsync(async () =>
+ {
+ var treeRoot = XamlReader.Load(@"
+
+
+
+
+
+
+
+
+
+
+") as FrameworkElement;
+
+ Assert.IsNotNull(treeRoot, "Could not load XAML tree.");
+
+ // Initialize Visual Tree
+ await LoadTestContentAsync(treeRoot);
+
+ var wrapPanel = treeRoot.FindChild("WrapPanel") as WrapPanel;
+ Assert.IsNotNull(wrapPanel, "Could not find WrapPanel in tree.");
+ Assert.IsTrue(wrapPanel.IsLoaded, "WrapPanel is not loaded.");
+ });
+ }
+}
diff --git a/components/Primitives/tests/WrapPanel/WrapPanelSample.xaml b/components/Primitives/tests/WrapPanel/WrapPanelSample.xaml
new file mode 100644
index 00000000..de967b81
--- /dev/null
+++ b/components/Primitives/tests/WrapPanel/WrapPanelSample.xaml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
diff --git a/components/Primitives/tests/WrapPanel/WrapPanelSample.xaml.cs b/components/Primitives/tests/WrapPanel/WrapPanelSample.xaml.cs
new file mode 100644
index 00000000..747df932
--- /dev/null
+++ b/components/Primitives/tests/WrapPanel/WrapPanelSample.xaml.cs
@@ -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 WrapPanelSample : Page
+{
+ public WrapPanelSample()
+ {
+ this.InitializeComponent();
+ }
+}