{"record":{"id":"cb738ecaa5fc76a7","repo":"dotnet/wpf","slug":"sr-format-sr-eventtriggerbadaction-value-gettype-name","errorCode":null,"errorMessage":"SR.Format(SR.EventTriggerBadAction, value.GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.EventTriggerBadAction, value\\.GetType\\(\\)\\.Name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/EventTrigger.cs","lineNumber":57,"sourceCode":"        }\n\n        /// <summary>\n        ///  Add an object child to this trigger's Actions\n        /// </summary>\n        void IAddChild.AddChild(object value)\n        {\n            AddChild(value);\n        }\n\n        /// <summary>\n        ///  Add an object child to this trigger's Actions\n        /// </summary>\n        protected virtual void AddChild(object value)\n        {\n            TriggerAction action = value as TriggerAction;\n            if (action == null)\n            {\n                throw new ArgumentException(SR.Format(SR.EventTriggerBadAction, value.GetType().Name));\n            }\n            Actions.Add(action);\n        }\n\n        /// <summary>\n        ///  Add a text string to this trigger's Actions.  Note that this\n        ///  is not supported and will result in an exception.\n        /// </summary>\n        void IAddChild.AddText(string text)\n        {\n            AddText(text);\n        }\n\n        /// <summary>\n        ///  Add a text string to this trigger's Actions.  Note that this\n        ///  is not supported and will result in an exception.\n        /// </summary>\n        protected virtual void AddText(string text)","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/EventTrigger.cs#L39-L75","documentation":"EventTrigger.AddChild accepts only TriggerAction objects for its Actions collection. Passing any other object type throws ArgumentException with EventTriggerBadAction including the value's actual type name.","triggerScenarios":"XAML like <EventTrigger><SomeNonActionElement/></EventTrigger>, or calling AddChild(value) programmatically with a non-TriggerAction object.","commonSituations":"XAML typos nesting unsupported elements inside EventTrigger; misremembering that EventTrigger children must be actions (BeginStoryboard, SoundPlayerAction, etc.); tooling that emits wrong child elements.","solutions":["Only place TriggerAction-derived elements inside EventTrigger (e.g. <BeginStoryboard>, <SoundPlayerAction>)","Wrap animations in <BeginStoryboard><Storyboard>...</Storyboard></BeginStoryboard>","Remove the invalid child element from the EventTrigger"],"exampleFix":"<!-- before -->\n<EventTrigger RoutedEvent=\"Button.Click\">\n  <Storyboard/> <!-- throws -->\n</EventTrigger>\n<!-- after -->\n<EventTrigger RoutedEvent=\"Button.Click\">\n  <BeginStoryboard><Storyboard/></BeginStoryboard>\n</EventTrigger>","handlingStrategy":"type-guard","validationCode":"if (child is not TriggerAction) throw new ArgumentException(\"EventTrigger children must be TriggerAction instances\");","typeGuard":"bool IsTriggerAction(object v) => v is TriggerAction;","tryCatchPattern":"try { trigger.AddChild(value); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"action\")) { wrapInBeginStoryboard(value); }","preventionTips":["Only nest TriggerAction-derived elements inside EventTrigger","Wrap Storyboards in BeginStoryboard"],"tags":["wpf","xaml","eventtrigger","animation"],"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"}