{"record":{"id":"0be56f20e3d92d29","repo":"dotnet/wpf","slug":"sr-format-sr-cannotchangeaftersealed-trigger","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/Trigger.cs","lineNumber":39,"sourceCode":"        [Ambient]\n        [Localizability(LocalizationCategory.None, Modifiability = Modifiability.Unmodifiable, Readability = Readability.Unreadable)] // Not localizable by-default\n        public DependencyProperty Property\n        {\n            get\n            {\n                // Verify Context Access\n                VerifyAccess();\n\n                return _property;\n            }\n            set\n            {\n                // Verify Context Access\n                VerifyAccess();\n\n                if (IsSealed)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"Trigger\"));\n                }\n\n                _property = value;\n            }\n        }\n\n        /// <summary>\n        ///     Value of the condition (equality check)\n        /// </summary>\n        [DependsOn(\"Property\")]\n        [DependsOn(\"SourceName\")]\n        [Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)] // Not localizable by-default\n        [TypeConverter(typeof(SetterTriggerConditionValueConverter))]\n        public object Value\n        {\n            get\n            {\n                // Verify Context Access","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs#L21-L57","documentation":"Trigger.Property has a setter that throws InvalidOperationException once the Trigger has been sealed (attached to a sealed Style/template). WPF seals triggers when the owning style is sealed so shared style state cannot be mutated. This protects thread-safety and consistency of sealed styles.","triggerScenarios":"Setting trigger.Property on a Trigger instance that was already used in a Style whose resources were sealed, e.g. modifying a Style.Triggers entry after Style.Seal() or after the style is applied/frozen.","commonSituations":"Mutating a style's triggers at runtime after the style was applied to controls; reusing one Trigger object across styles and editing it later.","solutions":["Create a new Trigger instance and set Property on it, then rebuild/replace the style before applying it.","Build the complete Trigger (Property, Value, Setters) before adding it to Style.Triggers.","If the style must change at runtime, construct a new Style with the modified trigger and assign it."],"exampleFix":"// before\nsealedTrigger.Property = UIElement.OpacityProperty; // throws\n// after\nvar trigger = new Trigger { Property = UIElement.OpacityProperty, Value = 0.5 };\nstyle.Triggers.Add(trigger);","handlingStrategy":"validation","validationCode":"if (trigger.IsSealed) throw new InvalidOperationException(\"Create a new Trigger instead of mutating a sealed one\");","typeGuard":"static bool IsEditable(Trigger t) => t != null && !t.IsSealed;","tryCatchPattern":"try { trigger.Property = p; }\ncatch (InvalidOperationException) { var replacement = new Trigger { Property = p, Value = trigger.Value }; style.Triggers[style.Triggers.IndexOf(trigger)] = replacement; }","preventionTips":["Fully configure Trigger (Property/Value/Setters) before adding to a style","Treat sealed styles as immutable; build a new Style for runtime changes","Never cache and later mutate shared Trigger instances"],"tags":["wpf","trigger","invalid-operation","sealed-style"],"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"}