dotnet/wpf · error · ArgumentException
SR.Format(SR.EventTriggerBadAction, value.GetType().Name)
Error message
SR.Format(SR.EventTriggerBadAction, value.GetType().Name)
What it means
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.
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
Example fix
<!-- before --> <EventTrigger RoutedEvent="Button.Click"> <Storyboard/> <!-- throws --> </EventTrigger> <!-- after --> <EventTrigger RoutedEvent="Button.Click"> <BeginStoryboard><Storyboard/></BeginStoryboard> </EventTrigger>
Defensive patterns
Strategy: type-guard
Validate before calling
if (child is not TriggerAction) throw new ArgumentException("EventTrigger children must be TriggerAction instances"); Type guard
bool IsTriggerAction(object v) => v is TriggerAction;
Try / catch
try { trigger.AddChild(value); }
catch (ArgumentException ex) when (ex.Message.Contains("action")) { wrapInBeginStoryboard(value); } Prevention
- Only nest TriggerAction-derived elements inside EventTrigger
- Wrap Storyboards in BeginStoryboard
When it happens
Trigger: XAML like <EventTrigger><SomeNonActionElement/></EventTrigger>, or calling AddChild(value) programmatically with a non-TriggerAction object.
Common situations: XAML typos nesting unsupported elements inside EventTrigger; misremembering that EventTrigger children must be actions (BeginStoryboard, SoundPlayerAction, etc.); tooling that emits wrong child elements.
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
- Animation_ChildMustBeKeyFrame
- Animation_ChildMustBeKeyFrame
- Animation_NoTextChildren
- Animation_NoTextChildren
- SR.Animation_ChildMustBeKeyFrame
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/cb738ecaa5fc76a7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/EventTrigger.cs:57
}
/// <summary>
/// Add an object child to this trigger's Actions
/// </summary>
void IAddChild.AddChild(object value)
{
AddChild(value);
}
/// <summary>
/// Add an object child to this trigger's Actions
/// </summary>
protected virtual void AddChild(object value)
{
TriggerAction action = value as TriggerAction;
if (action == null)
{
throw new ArgumentException(SR.Format(SR.EventTriggerBadAction, value.GetType().Name));
}
Actions.Add(action);
}
/// <summary>
/// Add a text string to this trigger's Actions. Note that this
/// is not supported and will result in an exception.
/// </summary>
void IAddChild.AddText(string text)
{
AddText(text);
}
/// <summary>
/// Add a text string to this trigger's Actions. Note that this
/// is not supported and will result in an exception.
/// </summary>
protected virtual void AddText(string text)View on GitHub (pinned to 81131a70a4)