{"record":{"id":"6381d669ef4b623a","repo":"dotnet/wpf","slug":"sr-mustbetriggeraction","errorCode":null,"errorMessage":"SR.MustBeTriggerAction","messagePattern":"SR\\.MustBeTriggerAction","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerActionCollection.cs","lineNumber":305,"sourceCode":"        // Throw if a change is attempted at a time we're not allowing them\n        private void CheckSealed()\n        {\n            if ( _sealed )\n            {\n                throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"TriggerActionCollection\"));\n            }            \n        }\n\n        // Throw if the given object isn't a TriggerAction\n        private TriggerAction VerifyIsTriggerAction(object value)\n        {\n            TriggerAction action = value as TriggerAction;\n\n            if ( action == null )\n            {\n                ArgumentNullException.ThrowIfNull(value);\n\n                throw new ArgumentException(SR.MustBeTriggerAction);\n            }\n\n            return action;\n        }\n\n\n\n        // The actual underlying storage for our TriggerActions\n        private List<TriggerAction> _rawList;\n\n        // Whether we are allowing further changes to the collection\n        private bool _sealed = false;\n\n        // The event trigger that we're in\n        private DependencyObject _owner = null;\n        \n    }\n}","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerActionCollection.cs#L287-L323","documentation":"TriggerActionCollection.VerifyIsTriggerAction throws ArgumentException with SR.MustBeTriggerAction when an object that is not a TriggerAction is added to or removed from a TriggerActionCollection. If the value is null it throws ArgumentNullException instead; otherwise a non-null, wrong-typed object reaches this guard.","triggerScenarios":"Passing a Setter, Trigger, arbitrary DependencyObject, or other non-TriggerAction object to Actions.Add/Insert/indexer-set/Remove/Contains/IndexOf of a TriggerActionCollection.","commonSituations":"XAML where a <Setter> is nested inside <Trigger.Actions> instead of <Trigger.Setters>; code-built triggers placing wrong items in the collection.","solutions":["Only add instances of TriggerAction subclasses (e.g., InvokeCommandAction, EventTrigger actions) to Actions","Move Setter elements into the trigger's Setters collection, not Actions","Check 'is TriggerAction' before Add/Insert"],"exampleFix":"// before\ntrigger.Actions.Add(new Setter.PropertySetter()); // wrong type\n// after\nif (item is TriggerAction ta) { trigger.Actions.Add(ta); }\nelse { trigger.Setters.Add((SetterBase)item); }","handlingStrategy":"type-guard","validationCode":"if (item is TriggerAction) { actions.Add(item); } else { throw new ArgumentException(nameof(item)); }","typeGuard":"static bool IsTriggerAction(object o) => o is TriggerAction;","tryCatchPattern":"try { actions.Add(item); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"TriggerAction\")) { /* wrong item type */ }","preventionTips":["Only add TriggerAction subclasses to Actions collections","Keep Setters in Setters, Actions in Actions in XAML","Use collection generics typed to TriggerAction in code"],"tags":["wpf","type-mismatch","argument-validation","xaml"],"backgroundTag":"type-mismatch","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"}