{"record":{"id":"3ff4419f5480bff2","repo":"dotnet/maui","slug":"flyout-must-not-already-have-a-parent","errorCode":null,"errorMessage":"Flyout must not already have a parent.","messagePattern":"Flyout must not already have a parent\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/FlyoutPage/FlyoutPage.cs","lineNumber":124,"sourceCode":"\t\t}\n\n\t\t/// <summary>Gets or sets the flyout page that is used to present a menu or navigation options.</summary>\n\t\tpublic Page Flyout\n\t\t{\n\t\t\tget { return _flyout; }\n\t\t\tset\n\t\t\t{\n\t\t\t\tif (_flyout != null && value == null)\n\t\t\t\t\tthrow new ArgumentNullException(nameof(value), \"Flyout cannot be set to null once a value is set\");\n\n\t\t\t\tif (string.IsNullOrEmpty(value.Title))\n\t\t\t\t\tthrow new InvalidOperationException(\"Title property must be set on Flyout page\");\n\n\t\t\t\tif (_flyout == value)\n\t\t\t\t\treturn;\n\n\t\t\t\tif (value.RealParent != null)\n\t\t\t\t\tthrow new InvalidOperationException(\"Flyout must not already have a parent.\");\n\n\t\t\t\t// TODO MAUI refine this to fire earlier\n\t\t\t\tvar previousFlyout = _flyout;\n\t\t\t\t\n\t\t\t\t// TODO MAUI refine this to fire earlier\n\t\t\t\tpreviousFlyout?.SendNavigatingFrom(new NavigatingFromEventArgs(value, NavigationType.Replace));\n\n\t\t\t\tOnPropertyChanging();\n\t\t\t\tif (_flyout != null)\n\t\t\t\t\tInternalChildren.Remove(_flyout);\n\t\t\t\t_flyout = value;\n\t\t\t\tInternalChildren.Add(_flyout);\n\t\t\t\tOnPropertyChanged();\n\n\t\t\t\tif (this.HasAppeared)\n\t\t\t\t{\n\t\t\t\t\tpreviousFlyout?.SendDisappearing();\n\t\t\t\t\t_flyout?.SendAppearing();","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs#L106-L142","documentation":"FlyoutPage.Flyout setter throws InvalidOperationException when the incoming Page already has a RealParent. A Maui Element may belong to only one parent; assigning an already-parented page as Flyout would detach it inconsistently from its current container.","triggerScenarios":"Assigning a Page to Flyout that is currently the Detail, a child of another FlyoutPage, the root of a NavigationPage, or a child of any Layout.","commonSituations":"Swapping Flyout and Detail using the same instance, sharing a menu page across multiple FlyoutPages, or reusing a page from a navigation stack.","solutions":["Instantiate a new Page for the Flyout assignment.","Detach the page from its current parent (reassign the old container's property) before reusing.","Never reuse a single Page instance as both Flyout and Detail.","Validate `value.RealParent == null` before assigning."],"exampleFix":"// before\nflyoutPage.Flyout = flyoutPage.Detail; // Detail already parented\n\n// after\nflyoutPage.Flyout = new FlyoutMenuPage();","handlingStrategy":"validation","validationCode":"if (value.RealParent != null) throw new InvalidOperationException(\"Page already parented\"); flyoutPage.Flyout = value;","typeGuard":"static bool IsUnparented(Page p) => p.RealParent is null;","tryCatchPattern":"try { flyoutPage.Flyout = value; } catch (InvalidOperationException) { flyoutPage.Flyout = value.Clone() /* or new instance */; }","preventionTips":["Never reuse a Page as both Flyout and Detail.","Instantiate fresh pages for each FlyoutPage.","Check RealParent before assigning."],"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"}