diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Events.cs b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Events.cs index 3766119fc77..307453ea967 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Events.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter/GridSplitter.Events.cs @@ -2,6 +2,8 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using System.Collections.Generic; +using System.Linq; using Windows.System; using Windows.UI.Core; using Windows.UI.Xaml; @@ -239,9 +241,17 @@ private bool HorizontalMove(double horizontalChange) return true; } + var columnsWithAutomaticWidth = Resizable.ColumnDefinitions.Where(x => (x.Width.IsStar || x.Width.IsAuto) && x != CurrentColumn); + // if current column has fixed width then resize it if (!IsStarColumn(CurrentColumn)) { + // Check if all automatic width columns will respect min and max width after resize + if (!AreValidColumnWidths(columnsWithAutomaticWidth, horizontalChange * -1)) + { + return false; + } + // No need to check for the Column Min width because it is automatically respected if (!SetColumnWidth(CurrentColumn, horizontalChange, GridUnitType.Pixel)) { @@ -258,6 +268,15 @@ private bool HorizontalMove(double horizontalChange) return false; } + // Remove the Sibling as it will be checked during resize + columnsWithAutomaticWidth = columnsWithAutomaticWidth.Where(x => x != SiblingColumn); + + // Check if all automatic width columns will respect min and max width after resize + if (!AreValidColumnWidths(columnsWithAutomaticWidth, horizontalChange)) + { + return false; + } + if (!SetColumnWidth(SiblingColumn, horizontalChange * -1, GridUnitType.Pixel)) { return true; @@ -297,5 +316,18 @@ private bool HorizontalMove(double horizontalChange) return false; } + + private bool AreValidColumnWidths(IEnumerable columns, double horizontalChange) + { + foreach (var column in columns) + { + if (!IsValidColumnWidth(column, horizontalChange)) + { + return false; + } + } + + return true; + } } }