Forum Xamarin.Forms

How to add many children to a StackLayout without blocking the UI thread?

gogolongogolon Member ✭✭

I have a horizontal StackLayout, which is basically an imitation of a horizontal ListView. Every 30 secs I need to clear it and add a lot of children to it. Currently, the app hangs for few seconds when it comes to refreshing the layout. Is there a way to add so many views (around 100) to the StackLayout without blocking the UI thread? I've tried using an async task, but it causes an exception (only the original thread that created the view can touch it).

Here's the code I use:
for (int i = 0; i < placesGrids.Count(); ++i)
if (i + 1 != Places.Count())
var separator = new BoxView
CornerRadius = 10,
Color = Color.LightGray,
WidthRequest = 3,
Opacity = 0.25,
Margin = 7,
HorizontalOptions = LayoutOptions.Center


Best Answers


Sign In or Register to comment.