{"record":{"id":"02c466ebc7fd797b","repo":"dotnet/wpf","slug":"sr-format-sr-cannotchangeaftersealed-triggeraction","errorCode":null,"errorMessage":"SR.Format(SR.CannotChangeAfterSealed, \"TriggerAction\")","messagePattern":"SR\\.Format\\(SR\\.CannotChangeAfterSealed, \"TriggerAction\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerAction.cs","lineNumber":114,"sourceCode":"        /// validation checks to see if all parameters make sense.\n        /// </summary>\n        internal override void Seal()\n        {\n            if( IsSealed )\n            {\n                throw new InvalidOperationException(SR.TriggerActionAlreadySealed);\n            }\n            base.Seal();\n        }\n\n        /// <summary>\n        ///     Checks sealed status and throws exception if object is sealed\n        /// </summary>\n        internal void CheckSealed()\n        {\n            if( IsSealed )\n            {\n                throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"TriggerAction\"));\n            }\n        }\n\n        // Define the DO's inheritance context\n\n        internal override DependencyObject InheritanceContext\n        {\n            get { return _inheritanceContext; }\n        }\n\n        // Receive a new inheritance context (this will be a FE/FCE)\n        internal override void AddInheritanceContext(DependencyObject context, DependencyProperty property)\n        {\n            InheritanceContextHelper.AddInheritanceContext(context,\n                                                              this,\n                                                              ref _hasMultipleInheritanceContexts,\n                                                              ref _inheritanceContext);\n        }","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerAction.cs#L96-L132","documentation":"TriggerAction.CheckSealed() throws InvalidOperationException (CannotChangeAfterSealed, 'TriggerAction') when any mutation is attempted on a TriggerAction after it has been sealed. Sealed objects are frozen into an immutable state once the owning Style/Template is applied, so later edits are rejected.","triggerScenarios":"Mutating properties of a TriggerAction (or its contents) after the containing Style/Template was applied to an element and thus sealed.","commonSituations":"Modifying a shared style's triggers at runtime after controls using it are rendered; changing EventSetter/InvokeCommandAction parameters from event handlers or timers.","solutions":["Clone the action (or define a new Style) before modifying, then re-apply the style","Create styles in XAML or before first use; avoid runtime mutation","Check the action's IsSealed property before mutating"],"exampleFix":"// before\nstyle.Triggers[0].Actions[0].Parameter = newValue; // throws if sealed\n// after\nvar newStyle = new Style { BasedOn = style };\nnewAction = new TriggerAction { Parameter = newValue };\nnewStyle.Triggers[0].Actions.Add(newAction);\ncontrol.Style = newStyle;","handlingStrategy":"validation","validationCode":"if (action.IsSealed) throw new InvalidOperationException(\"Action sealed; rebuild style before mutating.\");\naction.Parameter = newValue;","typeGuard":"static bool IsMutable(TriggerAction a) => a != null && !a.IsSealed;","tryCatchPattern":"try { action.Parameter = v; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"TriggerAction\")) { /* rebuild style */ }","preventionTips":["Configure triggers only during style construction","Clone styles before runtime edits","Avoid mutating shared/global styles after Window load"],"tags":["wpf","styles","sealed-object","immutability"],"backgroundTag":"invalid-state-transition","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"}