AvaloniaUI/Avalonia · error · ArgumentException

Transition elements have different parents.

Error message

Transition elements have different parents.

What it means

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.

Source

Thrown at samples/ControlCatalog/Pages/NavigationPage/Transitions/ParallaxSlideTransition.cs:117

                            }
                        }
                    }
                };
                tasks.Add(anim.RunAsync(to, cancellationToken));
            }

            await Task.WhenAll(tasks);

            if (from != null && !cancellationToken.IsCancellationRequested)
                from.IsVisible = false;
        }

        private static Visual GetVisualParent(Visual? from, Visual? to)
        {
            var p1 = (from ?? to)!.GetVisualParent();
            if (from != null && to != null &&
                !ReferenceEquals(from.GetVisualParent(), to.GetVisualParent()))
                throw new ArgumentException("Transition elements have different parents.");
            return p1 ?? throw new ArgumentException("Transition elements have no parent.");
        }
    }
}

View on GitHub (pinned to 11c5427268)

Solutions

  1. Ensure both 'from' and 'to' controls are children of the same parent panel before starting the transition.
  2. Reparent one control so both share a common parent, then run the transition.
  3. Pass null for 'from' on the first navigation so only one parent is required.
  4. Verify the visual tree has settled (both controls attached) before invoking GetVisualParent.

Example fix

// before
var parent = GetVisualParent(from, to); // from in Panel A, to in Panel B -> throws

// after
// move both controls into the same transition panel first
transitionPanel.Children.Add(to);
var parent = GetVisualParent(from, to);
Defensive patterns

Strategy: validation

Validate before calling

if (from != null && to != null && !ReferenceEquals(from.GetVisualParent(), to.GetVisualParent())) {
    // reparent one so they share a common parent before transitioning
}

Type guard

static bool ShareVisualParent(Visual? a, Visual? b) => a == null || b == null || ReferenceEquals(a.GetVisualParent(), b.GetVisualParent());

Try / catch

try { var p = GetVisualParent(from, to); }
catch (ArgumentException ex) when (ex.Message.Contains("different parents")) { /* reparent and retry */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/2d3417699f493253. Report an issue: GitHub.