diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Primitives/StaggeredLayout/StaggeredLayout.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Primitives/StaggeredLayout/StaggeredLayout.cs index fb94cf42878..470aad9ac96 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Primitives/StaggeredLayout/StaggeredLayout.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Primitives/StaggeredLayout/StaggeredLayout.cs @@ -147,14 +147,16 @@ protected override Size MeasureOverride(VirtualizingLayoutContext context, Size double availableWidth = availableSize.Width; double availableHeight = availableSize.Height; - double columnWidth = Math.Min(DesiredColumnWidth, availableWidth); + // This ternary prevents the column width from being NaN, which would otherwise cause an exception when measuring item sizes + double columnWidth = double.IsNaN(DesiredColumnWidth) ? availableWidth : Math.Min(DesiredColumnWidth, availableWidth); if (columnWidth != state.ColumnWidth) { // The items will need to be remeasured state.Clear(); } - state.ColumnWidth = Math.Min(DesiredColumnWidth, availableWidth); + // This ternary prevents the column width from being NaN, which would otherwise cause an exception when measuring item sizes + state.ColumnWidth = double.IsNaN(DesiredColumnWidth) ? availableWidth : Math.Min(DesiredColumnWidth, availableWidth); int numColumns = Math.Max(1, (int)Math.Floor(availableWidth / state.ColumnWidth)); // adjust for column spacing on all columns expect the first