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.
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;
}
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
Actual Behavior
When more than 200 Entry views are added:
Steps to Reproduce
public class MainPage : ContentPage
{
}`
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
shellPlease check the sample attached using Google drive
https://drive.google.com/file/d/17PdUB4m5sLexsEW5VQpZlHS4ko7rV1_w/view