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
3 changes: 2 additions & 1 deletion components/Primitives/src/WrapPanel/WrapPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Preview

Copilot AI Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Using 'is false' pattern is less readable than the negation operator. Consider using '!double.IsInfinity(parentMeasure.U)' for better readability and consistency with common C# practices.

Suggested change
if (isLast && double.IsInfinity(parentMeasure.U) is false)
if (isLast && !double.IsInfinity(parentMeasure.U))

Copilot uses AI. Check for mistakes.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I accidentally hit this button... interesting.

{
desiredMeasure.U = parentMeasure.U - position.U;
}
Expand Down
8 changes: 8 additions & 0 deletions components/Primitives/tests/Primitives.Tests.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@
<Compile Include="$(MSBuildThisFileDirectory)Test_UniformGrid_FreeSpots.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Test_UniformGrid_RowColDefinitions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Test_WrapPanel_BasicLayout.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Test_WrapPanel_Infinity.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Test_WrapPanel_Visibility.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UniformGrid\AutoLayoutFixedElementZeroZeroSpecialPage.xaml.cs">
<DependentUpon>AutoLayoutFixedElementZeroZeroSpecialPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)WrapPanel\WrapPanelSample.xaml.cs">
<DependentUpon>WrapPanelSample.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Page Include="$(MSBuildThisFileDirectory)DockPanel\DockPanelSample.xaml">
Expand All @@ -47,6 +51,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)WrapPanel\WrapPanelSample.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Include="$(MSBuildThisFileDirectory)SwitchPresenter\SwitchConverterBrushSample.xaml">
Expand Down
48 changes: 48 additions & 0 deletions components/Primitives/tests/Test_WrapPanel_Infinity.cs
Original file line number Diff line number Diff line change
@@ -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(@"<Page
xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
xmlns:controls=""using:CommunityToolkit.WinUI.Controls"">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width=""Auto"" />
</Grid.ColumnDefinitions>
<controls:WrapPanel
x:Name=""WrapPanel""
Grid.Column=""0""
StretchChild=""Last"">
<Border />
<Border />
<Border />
</controls:WrapPanel>
</Grid>
</Page>") 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.");
});
}
}
18 changes: 18 additions & 0 deletions components/Primitives/tests/WrapPanel/WrapPanelSample.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Page
x:Class="PrimitivesTests.WrapPanelSample"
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"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
mc:Ignorable="d">

<!--
This is required for dynamic XAML loading.
See https://github.com/CommunityToolkit/WindowsCommunityToolkit/issues/1961
-->
<controls:WrapPanel />

</Page>
13 changes: 13 additions & 0 deletions components/Primitives/tests/WrapPanel/WrapPanelSample.xaml.cs
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 WrapPanelSample : Page
{
public WrapPanelSample()
{
this.InitializeComponent();
}
}
Loading