Skip to content

UI becomes unresponsive when adding more than 200 Entry children to AbsoluteLayout #34396

Description

@ThilagarajSF5012

Description

When adding a large number of Entry controls (more than 200) to an AbsoluteLayout in .NET MAUI, the UI becomes unresponsive and experiences significant freezes. The issue occurs during bulk addition where each Entry is added to the layout and assigned layout bounds synchronously on the UI thread.

Expected Behavior

  • Adding multiple Entry children to an AbsoluteLayout should remain smooth and responsive.
  • The UI should continue to accept user input and render updates normally, even when a large number of child views are added.
  • Bulk layout operations should not cause the UI thread to block or freeze.

Actual Behavior

When more than 200 Entry views are added:

  • The UI freezes temporarily or becomes completely unresponsive.
  • The freeze persists until the entire batch of Entry controls is processed.

Steps to Reproduce

  1. Create a new .NET MAUI app.
  2. Add the below contents in MainPage.xaml.cs, which programmatically adds 200 Entry controls into an AbsoluteLayout `

public class MainPage : ContentPage
{

public readonly record struct Widget(double X, double Y, double W, double H);
private readonly List<(Editor Editor, Widget Item)> items = new();
private Button addEditorsBtn;
private Button clickedBtn;
private  AbsoluteLayout _canvas;
private int clickCount = 1;
public MainPage()
{
    InitializeComponent();
    addEditorsBtn = new Button { Text = "Add 200 Editors" };
    addEditorsBtn.Clicked += OnAddEditorsClicked;

    clickedBtn = new Button { Text = "Clicked 0" };
    clickedBtn.Clicked += Button_Clicked;
    canvas = new AbsoluteLayout
    {
        WidthRequest = 2000,
        HeightRequest = 3000,
        BackgroundColor = Color.FromArgb("#202020")
    };

    var root = new Grid
    {
        Padding = new Thickness(12),
        RowDefinitions =
        {
            new RowDefinition { Height = GridLength.Auto },
            new RowDefinition { Height = GridLength.Auto },
            new RowDefinition { Height = GridLength.Star },
        }
    };

    var toolbar = new HorizontalStackLayout
    {
        Spacing = 8,
        Children =
        {
            addEditorsBtn,
            clickedBtn,
        }
    };

    root.Add(toolbar);
    Grid.SetRow(_statusLabel, 1);
    root.Add(_statusLabel);
    Grid.SetRow(_statusLabel, 1);

    var scroller = new ScrollView { Content = _canvas };
    Grid.SetRow(scroller, 2);
    root.Add(scroller);
    Content = root;
}

private void OnAddEditorsClicked(object? sender, EventArgs e)
{
   for (int i = 0; i < 200; i++)
    {
        double x = (i * 12) % 1800;
        double y = (i * 15) % 2800;
        double width = 120;
        double height = 30;

        var editor = new Editor
        {
            Text = $"Item {i}",
            FontSize = 12,
            BackgroundColor = Colors.Gray,
            TextColor = Colors.White,
            IsReadOnly = true
        };
        _items.Add((editor, new Widget(x, y, width, height)));
    }
    
    foreach (var editor in items)
    {
        Dispatcher.Dispatch(() =>
        {
            canvas.Children.Add(editor.Editor);
            AbsoluteLayout.SetLayoutBounds(
                editor.Editor,
                new Rect(editor.Item.X, editor.Item.Y, editor.Item.W, editor.Item.H));
        });
    }
}
private void Button_Clicked(object? sender, EventArgs e)
{
    clickedBtn.Text = "Clicked " + _clickCount.ToString();
    clickCount += 1;
}

}`

Link to public reproduction project repository

No response

Version with bug

10.0.40

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android, macOS

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

shell
Please check the sample attached using Google drive
https://drive.google.com/file/d/17PdUB4m5sLexsEW5VQpZlHS4ko7rV1_w/view

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-layoutStackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenterlayout-absoluteplatform/androidplatform/iosplatform/macosmacOS / Mac Catalysts/triagedIssue has been revieweds/verifiedVerified / Reproducible Issue ready for Engineering Triaget/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions