{"record":{"id":"5a967ba1e1d2bc7c","repo":"dotnet/wpf","slug":"sr-format-sr-cannotchangeaftersealed-trigger-triggerbase","errorCode":null,"errorMessage":"SR.Format(SR.CannotChangeAfterSealed, \"trigger\")","messagePattern":"SR\\.Format\\(SR\\.CannotChangeAfterSealed, \"trigger\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs","lineNumber":138,"sourceCode":"        /// If set to 'true', EnterActions will be executed immediately if the\n        ///  conditions are met, before any \"enter\" change has occurred.\n        /// </summary>\n\n        // This is on the assumption that the \"enter\" change has occurred already.\n        //  For example: <CheckBox IsChecked=\"true\" /> the IsChecked property\n        //  change occurred before the CheckBox Style/Template is applied.\n        [DefaultValue(false)]\n        public bool ExecuteEnterActionsOnApply\n        {\n            get\n            {\n                return _executeEnterActionsOnApply;\n            }\n            set\n            {\n                if (IsSealed)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"trigger\"));\n                }\n\n                _executeEnterActionsOnApply = value;\n            }\n        }\n\n        /// <summary>\n        /// If set to 'true', ExitActions will be executed immediately if the\n        ///  conditions are not met, before any \"exit\" change has occurred.\n        /// </summary>\n        [DefaultValue(false)]\n        public bool ExecuteExitActionsOnApply\n        {\n            get\n            {\n                return _executeExitActionsOnApply;\n            }\n            set","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs#L120-L156","documentation":"The ExecuteEnterActionsOnApply property setter on TriggerBase throws InvalidOperationException (CannotChangeAfterSealed, 'trigger') when set on a trigger whose owning Style/Template has been sealed. Once sealed, trigger configuration properties become immutable.","triggerScenarios":"Setting trigger.ExecuteEnterActionsOnApply after the trigger's style/template was applied to a live element.","commonSituations":"Toggling trigger apply-behavior at runtime from code; adjusting shared styles after the window is loaded.","solutions":["Set ExecuteEnterActionsOnApply when constructing the trigger, before applying the style","Clone/rebuild the style with the desired value and reassign it","Check trigger.IsSealed before writing the property"],"exampleFix":"// before\ntrigger.ExecuteEnterActionsOnApply = false; // throws after seal\n// after\nif (!trigger.IsSealed) { trigger.ExecuteEnterActionsOnApply = false; }\nelse { /* rebuild style with the flag set before apply */ }","handlingStrategy":"validation","validationCode":"if (!trigger.IsSealed) { trigger.ExecuteEnterActionsOnApply = value; }","typeGuard":"static bool CanConfigure(TriggerBase t) => t != null && !t.IsSealed;","tryCatchPattern":"try { trigger.ExecuteEnterActionsOnApply = v; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"trigger\")) { /* rebuild style */ }","preventionTips":["Set trigger flags at construction time","Don't mutate triggers of applied styles","Document shared styles as immutable once used"],"tags":["wpf","styles","sealed-object","property-set"],"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"}