microsoft / microsoft/microsoft-ui-xaml

FlowLayout: Rapid wheel scrolling variable-sized ItemsRepeater causes layout-cycle crash

Open
#11,888 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

area-Layouts bug
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

Describe the bug

Microsoft.UI.Xaml.Controls.FlowLayout enters a layout cycle when an ItemsRepeater contains variable-sized items and is scrolled quickly with the mouse wheel. The layout iteration countdown reaches zero and the app terminates with 0xC000027B.

This reproduces with the current experimental WinUI 3 implementation in Microsoft.WindowsAppSDK 2.4.1-experimental.

Why is this important?

FlowLayout cannot safely virtualize a basic collection whose items have different widths and heights. A normal rapid wheel-scroll gesture can terminate the application, so applications cannot use this layout for variable-sized content.

Steps to reproduce the bug

  1. Create a packaged C# WinUI 3 app referencing Microsoft.WindowsAppSDK 2.4.1-experimental.
  2. Replace MainWindow.xaml and MainWindow.xaml.cs with the minimal code below.
  3. Run the app.
  4. Move the pointer over the ScrollViewer.
  5. Scroll quickly with the mouse wheel.
MainWindow.xaml
<Window
    x:Class="FlowLayoutCycleRepro.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:FlowLayoutCycleRepro">
    <ScrollViewer
        Width="520"
        Height="320"
        HorizontalScrollMode="Disabled"
        VerticalScrollMode="Enabled">
        <ItemsRepeater ItemsSource="{x:Bind Items}">
            <ItemsRepeater.Layout>
                <FlowLayout />
            </ItemsRepeater.Layout>
            <ItemsRepeater.ItemTemplate>
                <DataTemplate x:DataType="local:ReproItem">
                    <Border
                        Width="{x:Bind Width}"
                        Height="{x:Bind Height}"
                        Background="SteelBlue">
                        <TextBlock
                            HorizontalAlignment="Center"
                            VerticalAlignment="Center"
                            Text="{x:Bind Label}" />
                    </Border>
                </DataTemplate>
            </ItemsRepeater.ItemTemplate>
        </ItemsRepeater>
    </ScrollViewer>
</Window>
MainWindow.xaml.cs
using Microsoft.UI.Xaml;
using System.Collections.Generic;
using System.Linq;

namespace FlowLayoutCycleRepro;

public sealed partial class MainWindow : Window
{
    public IReadOnlyList<ReproItem> Items { get; } = Enumerable.Range(1, 500)
        .Select(index => new ReproItem(
            $"Item {index}",
            72 + index % 4 * 20,
            52 + index % 3 * 12))
        .ToList();

    public MainWindow()
    {
        InitializeComponent();
    }
}

public sealed record ReproItem(string Label, double Width, double Height);

No navigation, event handlers, custom title bar, or application-specific layout code is involved.

Actual behavior

Rapid wheel scrolling produces:

Layout Iteration Countdown: 7. Launching Arrange Pass.
Layout Iteration Countdown: 6. Launching EffectiveViewport Pass.
Layout Iteration Countdown: 5. Raising LayoutUpdated Events.
Layout Iteration Countdown: 4. Launching Measure Pass.
Layout Iteration Countdown: 3. Launching Arrange Pass.
Layout Iteration Countdown: 2. Launching EffectiveViewport Pass.
Layout Iteration Countdown: 1. Raising LayoutUpdated Events.
Layout Iteration Countdown: 0. Launching Measure Pass.
Crash: Exception (0xC000027B)

Expected behavior

The collection scrolls and FlowLayout continues realizing and arranging items without entering a layout cycle.

NuGet package version

Microsoft.WindowsAppSDK 2.4.1-experimental

Windows version

Windows build 26200 (ARM64)

Additional context

  • The repro uses the default FlowLayout; no optional layout properties are needed.
  • The failure reproduces with 500 items whose widths and heights vary.
  • A 100-item variant did not reproduce on the first tested wheel gesture.
  • microsoft/microsoft-ui-xaml#2607 reported the same general symptom on the older WinUI stack and was closed as stale. This issue provides a current, minimal, deterministic WinUI 3 repro.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the provided MainWindow.xaml and MainWindow.xaml.cs reproduction with Microsoft.WindowsAppSDK 2.4.1-experimental, then inspect the FlowLayout and ItemsRepeater layout paths involved in scrolling and variable-sized items. Done means rapid wheel scrolling no longer reaches the layout iteration limit or terminates the app, while the collection continues realizing and arranging items.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
desktop, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.