{"record":{"id":"e0b6f73af57c1496","repo":"dotnet/maui","slug":"detail-must-not-already-have-a-parent","errorCode":null,"errorMessage":"Detail must not already have a parent.","messagePattern":"Detail must not already have a parent\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/FlyoutPage/FlyoutPage.cs","lineNumber":53,"sourceCode":"\n\t\tRect _flyoutBounds;\n\n\t\tIFlyoutPageController FlyoutPageController => this;\n\n\t\t/// <summary>Gets or sets the detail page that is used to display details about items on the flyout page.</summary>\n\t\tpublic Page Detail\n\t\t{\n\t\t\tget { return _detail; }\n\t\t\tset\n\t\t\t{\n\t\t\t\tif (_detail != null && value == null)\n\t\t\t\t\tthrow new ArgumentNullException(nameof(value), \"Detail cannot be set to null once a value is set.\");\n\n\t\t\t\tif (_detail == value)\n\t\t\t\t\treturn;\n\n\t\t\t\tif (value.RealParent != null)\n\t\t\t\t\tthrow new InvalidOperationException(\"Detail must not already have a parent.\");\n\n\t\t\t\tvar previousDetail = _detail;\n\n\t\t\t\tpreviousDetail?.SendNavigatingFrom(new NavigatingFromEventArgs(destinationPage: value, navigationType: NavigationType.Replace));\n\n\t\t\t\t// Update the detail property\n\t\t\t\tOnPropertyChanging();\n\t\t\t\tif (_detail is not null)\n\t\t\t\t\tInternalChildren.Remove(_detail);\n\t\t\t\t_detail = value;\n\t\t\t\tInternalChildren.Add(_detail);\n\t\t\t\tOnPropertyChanged();\n\n\t\t\t\t// Handle Appearing/Disappearing events if the FlyoutPage has appeared\n\t\t\t\tif (HasAppeared)\n\t\t\t\t{\n\t\t\t\t\tpreviousDetail?.SendDisappearing();\n\t\t\t\t\t_detail?.SendAppearing();","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs#L35-L71","documentation":"FlyoutPage.Detail setter throws InvalidOperationException when the incoming Page already has a RealParent, because an Element can only belong to one visual tree. Re-parenting a page that is still a child of another FlyoutPage, NavigationPage, or layout would corrupt both trees.","triggerScenarios":"Assigning a Page instance to Detail that is already a child of another container (another FlyoutPage.Detail, NavigationPage root, or a Layout's Children) without removing it first.","commonSituations":"Sharing a single Page instance across multiple FlyoutPage instances, reusing a cached detail page that was never detached, or moving a page between navigation stacks.","solutions":["Create a fresh Page instance for the new Detail rather than reusing one already parented.","Remove the page from its current parent before reassigning (set the old parent's corresponding property to a different page).","Avoid caching and reusing Page instances across containers; recreate them per navigation.","Check `value.RealParent == null` before assigning if reuse is intentional."],"exampleFix":"// before\nflyoutPage2.Detail = flyoutPage1.Detail; // already parented\n\n// after\nflyoutPage2.Detail = new MyDetailPage(); // fresh instance","handlingStrategy":"validation","validationCode":"if (value.RealParent != null) throw new InvalidOperationException(\"Page already parented\"); flyoutPage.Detail = value;","typeGuard":"static bool IsUnparented(Page p) => p.RealParent is null;","tryCatchPattern":"try { flyoutPage.Detail = value; } catch (InvalidOperationException) { flyoutPage.Detail = value.Clone() /* or new instance */; }","preventionTips":["Do not reuse a Page instance across containers.","Detach a page from its current parent before reassigning.","Check RealParent before assigning to Detail."],"tags":["maui","flyoutpage","element-tree","navigation"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}