dotnet / dotnet/docs-maui

Add note about Android control parenting when control already has a parent

Open
#1,923 3 comments 0 reactions 0 assignees View on GitHub
doc-enhancement Pri3
Dominant language
No language data
Stars
282
Forks
265
Avg merge
2d 2h
Merged PRs (30d)
19

Description

This is motivated by this issue: https://github.com/dotnet/maui/issues/15920

On Android you can't 'move' a control from one parent to another without first removing it from the first parent. This is different from other platforms where this is allowed.

The exception you get is `Java.Lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.`

I suggest updating the docs with the following:

1. Note this different in platforms where we talk about adding controls programatically
2. Include the exception text so that we get better SEO
3. Specify how to do it correctly in MAUI with the C# APIs (it's not Java, so you don't call `removeView()`)

cc @hartez

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.