From 79e5ea6639e08477e6992d2071042735cef90b15 Mon Sep 17 00:00:00 2001 From: Yimeng Wu Date: Mon, 13 Nov 2023 23:00:23 +0000 Subject: [PATCH] Port microsoft/microsoft-ui-xaml#3393 --- .../Layouts/FlowLayout/FlowLayoutAlgorithm.cs | 4 +- test/ModernWpfTestApp/RepeaterTestUIPage.xaml | 1 + .../RepeaterTestUIPage.xaml.cs | 5 +++ .../Samples/UniformGridLayoutDemo.xaml | 39 +++++++++++++++++++ .../Samples/UniformGridLayoutDemo.xaml.cs | 26 +++++++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 test/ModernWpfTestApp/Samples/UniformGridLayoutDemo.xaml create mode 100644 test/ModernWpfTestApp/Samples/UniformGridLayoutDemo.xaml.cs diff --git a/ModernWpf.Controls/Repeater/Layouts/FlowLayout/FlowLayoutAlgorithm.cs b/ModernWpf.Controls/Repeater/Layouts/FlowLayout/FlowLayoutAlgorithm.cs index 9c11f546..1b540ad5 100644 --- a/ModernWpf.Controls/Repeater/Layouts/FlowLayout/FlowLayoutAlgorithm.cs +++ b/ModernWpf.Controls/Repeater/Layouts/FlowLayout/FlowLayoutAlgorithm.cs @@ -355,7 +355,9 @@ private void Generate( { // Does not fit, wrap to the previous row var availableSizeMinor = OM.Minor(availableSize); - OM.SetMinorStart(ref currentBounds, !double.IsInfinity(availableSizeMinor) ? availableSizeMinor - OM.Minor(desiredSize) : 0.0); + // If the last available size is finite, start from end and subtract our desired size. + // Otherwise, look at the last extent and use that for positioning. + OM.SetMinorStart(ref currentBounds, !double.IsInfinity(availableSizeMinor) ? availableSizeMinor - OM.Minor(desiredSize) : OM.MinorSize(LastExtent) - OM.Minor(desiredSize)); OM.SetMajorStart(ref currentBounds, lineOffset - OM.Major(desiredSize) - lineSpacing); if (lineNeedsReposition) diff --git a/test/ModernWpfTestApp/RepeaterTestUIPage.xaml b/test/ModernWpfTestApp/RepeaterTestUIPage.xaml index 881ae468..6f99cad1 100644 --- a/test/ModernWpfTestApp/RepeaterTestUIPage.xaml +++ b/test/ModernWpfTestApp/RepeaterTestUIPage.xaml @@ -186,6 +186,7 @@ AutomationProperties.Name="Basic Demo"> Basic Demo + diff --git a/test/ModernWpfTestApp/RepeaterTestUIPage.xaml.cs b/test/ModernWpfTestApp/RepeaterTestUIPage.xaml.cs index f1f5791b..05221017 100644 --- a/test/ModernWpfTestApp/RepeaterTestUIPage.xaml.cs +++ b/test/ModernWpfTestApp/RepeaterTestUIPage.xaml.cs @@ -35,6 +35,11 @@ public RepeaterTestUIPage() Frame.NavigateWithoutAnimation(typeof(BasicDemo)); }; + uniformGridLayoutDemo.Click += delegate + { + Frame.NavigateWithoutAnimation(typeof(UniformGridLayoutDemo)); + }; + itemsSourceDemo.Click += delegate { Frame.NavigateWithoutAnimation(typeof(ElementsInItemsSourcePage)); diff --git a/test/ModernWpfTestApp/Samples/UniformGridLayoutDemo.xaml b/test/ModernWpfTestApp/Samples/UniformGridLayoutDemo.xaml new file mode 100644 index 00000000..27d1e0f7 --- /dev/null +++ b/test/ModernWpfTestApp/Samples/UniformGridLayoutDemo.xaml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/ModernWpfTestApp/Samples/UniformGridLayoutDemo.xaml.cs b/test/ModernWpfTestApp/Samples/UniformGridLayoutDemo.xaml.cs new file mode 100644 index 00000000..2952303d --- /dev/null +++ b/test/ModernWpfTestApp/Samples/UniformGridLayoutDemo.xaml.cs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See LICENSE in the project root for license information. + +using System.Collections.Generic; +using System.Linq; +using System.Windows; + +namespace MUXControlsTestApp.Samples +{ + public sealed partial class UniformGridLayoutDemo + { + public IEnumerable collection; + + public UniformGridLayoutDemo() + { + collection = Enumerable.Range(0, 40); + this.InitializeComponent(); + UniformGridRepeater.ItemsSource = collection; + } + + public void GetRepeaterActualHeightButtonClick(object sender, RoutedEventArgs e) + { + RepeaterActualHeightLabel.Text = UniformGridRepeater.ActualHeight.ToString(); + } + } +}