{"record":{"id":"2d3417699f493253","repo":"AvaloniaUI/Avalonia","slug":"transition-elements-have-different-parents","errorCode":null,"errorMessage":"Transition elements have different parents.","messagePattern":"Transition elements have different parents\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"samples/ControlCatalog/Pages/NavigationPage/Transitions/ParallaxSlideTransition.cs","lineNumber":117,"sourceCode":"                            }\n                        }\n                    }\n                };\n                tasks.Add(anim.RunAsync(to, cancellationToken));\n            }\n\n            await Task.WhenAll(tasks);\n\n            if (from != null && !cancellationToken.IsCancellationRequested)\n                from.IsVisible = false;\n        }\n\n        private static Visual GetVisualParent(Visual? from, Visual? to)\n        {\n            var p1 = (from ?? to)!.GetVisualParent();\n            if (from != null && to != null &&\n                !ReferenceEquals(from.GetVisualParent(), to.GetVisualParent()))\n                throw new ArgumentException(\"Transition elements have different parents.\");\n            return p1 ?? throw new ArgumentException(\"Transition elements have no parent.\");\n        }\n    }\n}\n","sourceCodeStart":99,"sourceCodeEnd":122,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/samples/ControlCatalog/Pages/NavigationPage/Transitions/ParallaxSlideTransition.cs#L99-L122","documentation":"Thrown by ParallaxSlideTransition.GetVisualParent (ArgumentException) when the 'from' and 'to' transition controls have different visual parents. ParallaxSlideTransition animates two elements that must share a common parent container, so mismatched parents make the animation geometry invalid.","triggerScenarios":"Invoking the transition with from != null and to != null where from.GetVisualParent() and to.GetVisualParent() return different objects. Happens when the two pages/controls are hosted in separate panels during a navigation transition.","commonSituations":"Controls reparented during navigation; a transition applied to elements that live in different Panels/Grids; custom layouts that move elements between containers before the transition runs.","solutions":["Ensure both 'from' and 'to' controls are children of the same parent panel before starting the transition.","Reparent one control so both share a common parent, then run the transition.","Pass null for 'from' on the first navigation so only one parent is required.","Verify the visual tree has settled (both controls attached) before invoking GetVisualParent."],"exampleFix":"// before\nvar parent = GetVisualParent(from, to); // from in Panel A, to in Panel B -> throws\n\n// after\n// move both controls into the same transition panel first\ntransitionPanel.Children.Add(to);\nvar parent = GetVisualParent(from, to);","handlingStrategy":"validation","validationCode":"if (from != null && to != null && !ReferenceEquals(from.GetVisualParent(), to.GetVisualParent())) {\n    // reparent one so they share a common parent before transitioning\n}","typeGuard":"static bool ShareVisualParent(Visual? a, Visual? b) => a == null || b == null || ReferenceEquals(a.GetVisualParent(), b.GetVisualParent());","tryCatchPattern":"try { var p = GetVisualParent(from, to); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"different parents\")) { /* reparent and retry */ }","preventionTips":["Ensure both transition elements share a parent panel before starting.","Pass null for 'from' on first navigation.","Let the visual tree settle before transitioning."],"tags":["sample","transition","animation","visual-tree","csharp","argument"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}