From 5072d89125ea7535f1df843db825db210fe975c2 Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Thu, 17 Jul 2025 12:54:18 +0900 Subject: [PATCH 1/3] Fix WrapPanel stretching behavior for last item Added a conditional check to prevent the last item in the WrapPanel from stretching when the parent measure's width is infinite. --- components/Primitives/src/WrapPanel/WrapPanel.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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; } From cece15f8899e6c59814b5f1ffa861aca04f724e0 Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Fri, 18 Jul 2025 13:26:53 +0900 Subject: [PATCH 2/3] Add a page with a WrapPanel to fix tests with dynamic XAML loading See #1961 for details. --- .../tests/Primitives.Tests.projitems | 7 +++++++ .../tests/WrapPanel/WrapPanelSample.xaml | 18 ++++++++++++++++++ .../tests/WrapPanel/WrapPanelSample.xaml.cs | 13 +++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 components/Primitives/tests/WrapPanel/WrapPanelSample.xaml create mode 100644 components/Primitives/tests/WrapPanel/WrapPanelSample.xaml.cs diff --git a/components/Primitives/tests/Primitives.Tests.projitems b/components/Primitives/tests/Primitives.Tests.projitems index 39e21d6d..23613404 100644 --- a/components/Primitives/tests/Primitives.Tests.projitems +++ b/components/Primitives/tests/Primitives.Tests.projitems @@ -37,6 +37,9 @@ AutoLayoutFixedElementZeroZeroSpecialPage.xaml + + WrapPanelSample.xaml + @@ -47,6 +50,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + 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(); + } +} From 121a7e32ac7681f9639bffa561004491c2268fca Mon Sep 17 00:00:00 2001 From: Andrew KeepCoding Date: Wed, 23 Jul 2025 16:07:22 +0900 Subject: [PATCH 3/3] Add WrapPanel infinity test case --- .../tests/Primitives.Tests.projitems | 1 + .../tests/Test_WrapPanel_Infinity.cs | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 components/Primitives/tests/Test_WrapPanel_Infinity.cs diff --git a/components/Primitives/tests/Primitives.Tests.projitems b/components/Primitives/tests/Primitives.Tests.projitems index 23613404..79523a18 100644 --- a/components/Primitives/tests/Primitives.Tests.projitems +++ b/components/Primitives/tests/Primitives.Tests.projitems @@ -33,6 +33,7 @@ + AutoLayoutFixedElementZeroZeroSpecialPage.xaml 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."); + }); + } +}