{"record":{"id":"f992c775bc8bc905","repo":"dotnet/wpf","slug":"animation-childmustbekeyframe","errorCode":"Animation_ChildMustBeKeyFrame","errorMessage":"SR.Animation_ChildMustBeKeyFrame (Animation_ChildMustBeKeyFrame)","messagePattern":"SR\\.Animation_ChildMustBeKeyFrame \\(Animation_ChildMustBeKeyFrame\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Animation/Generated/BooleanAnimationUsingKeyFrames.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            BooleanKeyFrame keyFrame = child as BooleanKeyFrame;\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/BooleanAnimationUsingKeyFrames.cs#L209-L245","documentation":"AddChild was called on a BooleanAnimationUsingKeyFrames (key-frame animation) with an object that is not an IKeyFrame — likely a Boolean. Key-frame animations accept only key frame children (BooleanKeyFrame instances such as DiscreteBooleanKeyFrame); anything else makes the content model invalid and an ArgumentException is thrown.","triggerScenarios":"In XAML, nesting a plain <sys:Boolean>true</sys:Boolean> element inside <BooleanAnimationUsingKeyFrames> instead of a key frame element; in code, calling AddChild(true) directly.","commonSituations":"Hand-editing XAML without the <DiscreteBooleanKeyFrame Value=\"True\" KeyTime=\"0:0:1\"/> wrapper; copy-pasting key-frame markup from Double animation samples; tooling that emits child values without key-frame wrappers.","solutions":["Wrap the value in a key frame: <DiscreteBooleanKeyFrame Value=\"True\" KeyTime=\"...\"/> instead of a bare Boolean child.","In code, use KeyFrames.Add(new DiscreteBooleanKeyFrame(true, KeyTime.FromTimeSpan(ts))) rather than AddChild.","Fix XAML generators/templates to always emit key frame elements as children of XxxAnimationUsingKeyFrames."],"exampleFix":"// before (XAML)\n<BooleanAnimationUsingKeyFrames>\n  <sys:Boolean>True</sys:Boolean>\n</BooleanAnimationUsingKeyFrames>\n// after\n<BooleanAnimationUsingKeyFrames>\n  <DiscreteBooleanKeyFrame Value=\"True\" KeyTime=\"0:0:1\"/>\n</BooleanAnimationUsingKeyFrames>","handlingStrategy":"type-guard","validationCode":"if (child is not IKeyFrame keyFrame)\n    throw new ArgumentException(\"Only key frame children (e.g. DiscreteBooleanKeyFrame) are allowed\", nameof(child));","typeGuard":"static bool IsKeyFrameChild(object child) => child is BooleanKeyFrame;","tryCatchPattern":"try { animation.AddChild(child); }\ncatch (ArgumentException) { animation.KeyFrames.Add(new DiscreteBooleanKeyFrame((bool)child, KeyTime.Uniform)); }","preventionTips":["In XAML always nest XxxKeyFrame elements inside XxxAnimationUsingKeyFrames.","Prefer KeyFrames.Add in code instead of AddChild.","Validate generated XAML against the content model."],"tags":["wpf","animation","xaml","keyframes","invalid-argument"],"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-21T21:30:21.729Z"}