Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix repeater page crash when resizing to a small width #1161

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Changes from all 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
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