HandyOrg/HandyControl · error · ArgumentException

Animation_ChildMustBeKeyFrame

Error message

Animation_ChildMustBeKeyFrame

What it means

GeometryAnimationUsingKeyFrames implements IAddChild so XAML can populate its KeyFrames collection; AddChild only accepts GeometryKeyFrame instances and throws ArgumentException("Animation_ChildMustBeKeyFrame", nameof(child)) for anything else. The content model of this animation is restricted to key frame children.

Solutions

  1. Use GeometryKeyFrame-derived children only: <GeometryKeyFrame Value="..." KeyTime="..." /> inside the animation element.
  2. Check element names in XAML match the geometry key frame types, not the double ones from copied examples.
  3. If you need simple from/to animation, use GeometryAnimation instead of the key-frames variant.

Example fix

// before
<GeometryAnimationUsingKeyFrames>
    <LinearDoubleKeyFrame Value="10" KeyTime="0:0:1" /> <!-- wrong type -->
</GeometryAnimationUsingKeyFrames>
// after
<GeometryAnimationUsingKeyFrames>
    <GeometryKeyFrame Value="M0,0 L10,10" KeyTime="0:0:1" />
</GeometryAnimationUsingKeyFrames>
Defensive patterns

Strategy: validation

Validate before calling

// XAML-time check: every child of GeometryAnimationUsingKeyFrames must be a GeometryKeyFrame element
// <GeometryKeyFrame Value="M0,0 L1,1" KeyTime="0:0:1" />

Try / catch

try { animation.AddChild(child); } catch (ArgumentException ex) when (ex.Message == "Animation_ChildMustBeKeyFrame") { // ignore or wrap child in a GeometryKeyFrame
}

Prevention

When it happens

Trigger: In XAML, declaring a child element inside <GeometryAnimationUsingKeyFrames> that is not a GeometryKeyFrame (e.g. a plain Geometry, DoubleAnimation, or GeometryAnimation).

Common situations: Copy-pasting children from a DoubleAnimationUsingKeyFrames (which uses DoubleKeyFrame children) into a Geometry key-frame animation; accidentally nesting another animation inside it.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of HandyOrg/HandyControl@2c0875ebd6 (2026-09-14). Data as JSON: /api/errors/b88d3a077ab06ad5. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/HandyControl_Shared/Media/Animation/GeometryAnimationUsingKeyFrames.cs:151

        {
            throw new ArgumentNullException(nameof(child));
        }

        AddChild(child);

        WritePostscript();
    }

    [EditorBrowsable(EditorBrowsableState.Advanced)]
    protected virtual void AddChild(object child)
    {
        if (child is GeometryKeyFrame keyFrame)
        {
            KeyFrames.Add(keyFrame);
        }
        else
        {
            throw new ArgumentException("Animation_ChildMustBeKeyFrame", nameof(child));
        }
    }

    void IAddChild.AddText(string childText)
    {
        if (childText == null)
        {
            throw new ArgumentNullException(nameof(childText));
        }

        AddText(childText);
    }

    [EditorBrowsable(EditorBrowsableState.Advanced)]
    protected virtual void AddText(string childText) => throw new InvalidOperationException("Animation_NoTextChildren");

    protected override Geometry GetCurrentValueCore(Geometry defaultOriginValue, Geometry defaultDestinationValue, AnimationClock animationClock)
    {

View on GitHub (pinned to 2c0875ebd6)