Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java.Lang.IllegalStateException: The specified child already has a parent. Easy to repro #20310

Closed
AlleSchonWeg opened this issue Feb 2, 2024 · 3 comments
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter platform/android 🤖 t/bug Something isn't working
Milestone

Comments

@AlleSchonWeg
Copy link
Contributor

AlleSchonWeg commented Feb 2, 2024

Description

If you remove a control from a layouts child collection the native parents are not set to null. This results in a crash, if you try to add it again.
Reprocode:

            LayoutGrid.Children.Remove(scroller);
            scroller.Content = null; //new Label(); //In XF this line sets the native parent from the "stack" to null. Not in MAUI
            Grid.SetRow(stack, 0);
            Grid.SetColumn(stack, 0);
            var platform = stack.Handler.PlatformView;
            LayoutGrid.Children.Add(stack);

scroller.Content sets the VirtualViews Parent to null, but not the PlatformViews Parent.

Steps to Reproduce

Click button in repro

Link to public reproduction project repository

MauiApp5.zip

No response

Version with bug

8.0.6

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android, Windows

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@AlleSchonWeg AlleSchonWeg added the t/bug Something isn't working label Feb 2, 2024
@rmarinho rmarinho added this to the Backlog milestone Feb 2, 2024
@ghost
Copy link

ghost commented Feb 2, 2024

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

@rmarinho rmarinho added the area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Feb 2, 2024
@mattleibow
Copy link
Member

Duplicate of #15920

@mattleibow mattleibow marked this as a duplicate of #15920 Feb 2, 2024
@AlleSchonWeg
Copy link
Contributor Author

@mattleibow Why is this by design?
Sometimes if you rotate the device you need to layout the UI completely different. So you have to rearrange the controls or need an additional scroll view. depending on your layout complexity.
Just setting scroller.Content = new Label () works. Setting to null causes the exception. 🤪

@github-actions github-actions bot locked and limited conversation to collaborators Mar 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-layout StackLayout, GridLayout, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter platform/android 🤖 t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants