{"record":{"id":"f370a7c353ec77c3","repo":"AvaloniaUI/Avalonia","slug":"cannot-determine-visual-parent-f370a7","errorCode":null,"errorMessage":"Cannot determine visual parent.","messagePattern":"Cannot determine visual parent\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Animation/PageSlide.cs","lineNumber":236,"sourceCode":"        /// <param name=\"to\">The to control.</param>\n        /// <returns>The common parent.</returns>\n        /// <exception cref=\"ArgumentException\">\n        /// The two controls do not share a common parent.\n        /// </exception>\n        /// <remarks>\n        /// Any one of the parameters may be null, but not both.\n        /// </remarks>\n        protected static Visual GetVisualParent(Visual? from, Visual? to)\n        {\n            var p1 = (from ?? to)!.VisualParent;\n            var p2 = (to ?? from)!.VisualParent;\n\n            if (p1 != null && p2 != null && p1 != p2)\n            {\n                throw new ArgumentException(\"Controls for PageSlide must have same parent.\");\n            }\n\n            return p1 ?? throw new InvalidOperationException(\"Cannot determine visual parent.\");\n        }\n    }\n}\n","sourceCodeStart":218,"sourceCodeEnd":240,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Animation/PageSlide.cs#L218-L240","documentation":"Thrown by PageSlide.GetVisualParent when the resolved parent p1 is null, meaning neither 'from' nor 'to' has a VisualParent. The transition cannot position or animate controls that are detached from the visual tree.","triggerScenarios":"Calling PageSlide with two controls that are both unparented (not yet added to any visual); calling it after both controls were removed from the tree; passing two nulls (GetVisualParent requires at least one non-null).","commonSituations":"Invoking a page transition in a constructor or handler before the controls are attached; animating freshly-created controls that were never added to a panel.","solutions":["Add at least one of the controls to a parent panel before starting the slide.","Defer the transition until both controls report a non-null Parent/VisualParent.","If a control was removed, re-parent it or pass it as the null argument."],"exampleFix":"// before\nvar slide = new PageSlide();\nslide.Start(from: detachedA, to: detachedB); // both unparented\n\n// after\npanel.Children.Add(detachedA);\npanel.Children.Add(detachedB);\nslide.Start(from: detachedA, to: detachedB);","handlingStrategy":"validation","validationCode":"static bool HasAnyParent(Visual? a, Visual? b) =>\n    (a ?? b)?.VisualParent is not null;","typeGuard":null,"tryCatchPattern":"if (!HasAnyParent(from, to)) { panel.Children.Add(to); }\nslide.Start(from, to);","preventionTips":["Ensure at least one control is attached before invoking the transition.","Defer transitions until OnAttachedToVisualTree."],"tags":["animation","pageslide","visual-tree","invalid-operation"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}