{"record":{"id":"5c44c16ed9f5d23e","repo":"dotnet/wpf","slug":"sr-animation-childmustbekeyframe-5c44c1","errorCode":null,"errorMessage":"SR.Animation_ChildMustBeKeyFrame","messagePattern":"SR\\.Animation_ChildMustBeKeyFrame","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/DoubleAnimationUsingKeyFrames.cs","lineNumber":227,"sourceCode":"            WritePostscript();\n        }\n\n        /// <summary>\n        /// Implemented to allow KeyFrames to be direct children\n        /// of KeyFrameAnimations in markup.\n        /// </summary>\n        [EditorBrowsable(EditorBrowsableState.Advanced)]\n        protected virtual void AddChild(object child)\n        {\n            DoubleKeyFrame keyFrame = child as DoubleKeyFrame;\n\n            if (keyFrame != null)\n            {\n                KeyFrames.Add(keyFrame);\n            }\n            else\n            {        \n                throw new ArgumentException(SR.Animation_ChildMustBeKeyFrame, nameof(child));\n            }\n        }\n\n        /// <summary>\n        /// Adds a text string as a child of this KeyFrameAnimation.\n        /// </summary>\n        /// <param name=\"childText\">\n        /// The text to add.\n        /// </param>\n        /// <remarks>\n        /// A KeyFrameAnimation does not accept text as a child, so this method will\n        /// raise an InvalididOperationException unless a derived class has\n        /// overridden the behavior to add text.\n        /// </remarks>\n        /// <exception cref=\"ArgumentNullException\">The childText parameter is\n        /// null.</exception>\n        void IAddChild.AddText(string childText)\n        {","sourceCodeStart":209,"sourceCodeEnd":245,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/DoubleAnimationUsingKeyFrames.cs#L209-L245","documentation":"DoubleAnimationUsingKeyFrames.AddChild throws ArgumentException(SR.Animation_ChildMustBeKeyFrame) when something other than a DoubleKeyFrame (or null) is added as a child of the key-frame animation in XAML/object-model composition. Only key frames may be children of a KeyFrameAnimation.","triggerScenarios":"Adding a child object that is not a DoubleKeyFrame to DoubleAnimationUsingKeyFrames — e.g. via IAddChild.AddChild from parsed XAML like <DoubleAnimationUsingKeyFrames><DoubleAnimation .../></DoubleAnimationUsingKeyFrames>, or calling AddChild directly with a non-keyframe/null object.","commonSituations":"XAML typos where a plain animation or timeline is nested inside a key-frame animation instead of a DoubleKeyFrame (DiscreteDoubleKeyFrame, LinearDoubleKeyFrame, SplineDoubleKeyFrame, EasingDoubleKeyFrame); programmatic AddChild misuse.","solutions":["Nest only DoubleKeyFrame-derived elements inside DoubleAnimationUsingKeyFrames","Use explicit key-frame elements such as <LinearDoubleKeyFrame Value=\"10\" KeyTime=\"0:0:1\"/> in XAML","In code, call KeyFrames.Add(new DoubleKeyFrame...) instead of AddChild"],"exampleFix":"// before (XAML)\n<DoubleAnimationUsingKeyFrames>\n  <DoubleAnimation To=\"100\" />\n</DoubleAnimationUsingKeyFrames>\n// after\n<DoubleAnimationUsingKeyFrames>\n  <LinearDoubleKeyFrame Value=\"100\" KeyTime=\"0:0:1\" />\n</DoubleAnimationUsingKeyFrames>","handlingStrategy":"validation","validationCode":"if (child == null || child is not DoubleKeyFrame) throw new ArgumentException(\"Child must be a DoubleKeyFrame\", nameof(child));","typeGuard":"static bool IsValidKeyFrameChild(object child) => child is DoubleKeyFrame;","tryCatchPattern":"try { anim.AddChild(o); } catch (ArgumentException ex) { /* wrong child type — use KeyFrames.Add instead */ }","preventionTips":["Only nest DoubleKeyFrame-derived elements inside DoubleAnimationUsingKeyFrames in XAML","Prefer the typed KeyFrames.Add API over IAddChild.AddChild in code","Match key-frame element type to the animation's value type"],"tags":["wpf","animation","xaml","keyframes","invalid-child"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}