When assigning to Content for a second time in a MAUI app page, I get the following error:
The specified child already has a parent. You must call removeView() on the child’s parent first.
Showing my code first, then the solution I found.
activityIndicator = new ActivityIndicator { Color = Colors.White };
activityIndicatorStackLayout = new VerticalStackLayout
{
HeightRequest = 60D,
WidthRequest = 60D,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
Children = { activityIndicator }
};
Content = activityIndicatorStackLayout;
....
....
....
....
Content = new VerticalStackLayout
{
Spacing = 25D,
Children =
{
upperStackLayout,
activityIndicator
}
};
Posting here the solution I found.
1
The parent of activityIndicator is activityIndicatorStackLayout.
One solution is to use activityIndicator everywhere, instead of activityIndicatorStackLayout.
The solution I chose was to replace activityIndicator with activityIndicatorStackLayout in the second Content assignment:
Content = new VerticalStackLayout
{
Spacing = 25D,
Children =
{
upperStackLayout,
activityIndicatorStackLayout
}
};
Seems like it might be a Maui bug – worked in Xamarin.