Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
9 changes: 8 additions & 1 deletion components/Primitives/src/WrapPanel/WrapPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public Thickness Padding
/// <summary>
/// Gets or sets a value indicating how to arrange child items
/// </summary>
/// <remarks>
/// When the available size provided to the panel is infinite (for example,
/// when placed in a container with Auto sizing), the last child will not be
/// stretched. Attempting to stretch in this scenario would cause the element
/// to expand to an infinite size and result in a runtime exception.
/// </remarks>
public StretchChild StretchChild
{
get { return (StretchChild)GetValue(StretchChildProperty); }
Expand Down Expand Up @@ -219,7 +225,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))
{
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.");
});
}
}
17 changes: 17 additions & 0 deletions components/Primitives/tests/WrapPanel/WrapPanelSample.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<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