Skip to content

Commit

Permalink
Merge pull request #1161 from microsoft/user/ranjeshj/repeaterpagecrash
Browse files Browse the repository at this point in the history
fix repeater page crash when resizing to a small width
  • Loading branch information
ranjeshj authored Jan 9, 2023
2 parents bd4d0be + d7d972f commit 67f2c29
Showing 1 changed file with 20 additions and 23 deletions.
43 changes: 20 additions & 23 deletions WinUIGallery/Common/VariedImageSizeLayout.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using Windows.Foundation;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;

using VirtualizingLayout = Microsoft.UI.Xaml.Controls.VirtualizingLayout;
using VirtualizingLayoutContext = Microsoft.UI.Xaml.Controls.VirtualizingLayoutContext;


namespace AppUIBasics.Common
{
public class VariedImageSizeLayout : VirtualizingLayout
Expand All @@ -37,7 +34,7 @@ protected override Size MeasureOverride(VirtualizingLayoutContext context, Size
}

// Initialize column offsets
int numColumns = (int)(availableSize.Width / Width);
int numColumns = Math.Max(1, (int)(availableSize.Width / Width));
if (m_columnOffsets.Count == 0)
{
for (int i = 0; i < numColumns; i++)
Expand Down Expand Up @@ -99,7 +96,7 @@ protected override Size ArrangeOverride(VirtualizingLayoutContext context, Size

private void UpdateCachedBounds(Size availableSize)
{
int numColumns = (int)(availableSize.Width / Width);
int numColumns = Math.Max(1, (int)(availableSize.Width / Width));
m_columnOffsets.Clear();
for (int i = 0; i < numColumns; i++)
{
Expand Down Expand Up @@ -144,22 +141,22 @@ private int GetStartIndex(Rect viewport)
return startIndex;
}

private int GetIndexOfLowestColumn(List<double> columnOffsets, out double lowestOffset)
{
int lowestIndex = 0;
lowestOffset = columnOffsets[lowestIndex];
for (int index = 0; index < columnOffsets.Count; index++)
{
var currentOffset = columnOffsets[index];
if (lowestOffset > currentOffset)
{
lowestOffset = currentOffset;
lowestIndex = index;
}
}

return lowestIndex;
}
private int GetIndexOfLowestColumn(List<double> columnOffsets, out double lowestOffset)
{
int lowestIndex = 0;
lowestOffset = columnOffsets[lowestIndex];
for (int index = 0; index < columnOffsets.Count; index++)
{
var currentOffset = columnOffsets[index];
if (lowestOffset > currentOffset)
{
lowestOffset = currentOffset;
lowestIndex = index;
}
}

return lowestIndex;
}

private Size GetExtentSize(Size availableSize)
{
Expand Down

0 comments on commit 67f2c29

Please sign in to comment.