{"record":{"id":"e778452e80f350d0","repo":"dotnet/wpf","slug":"sr-format-sr-cannotchangeaftersealed-datatrigger","errorCode":null,"errorMessage":"SR.Format(SR.CannotChangeAfterSealed, \"DataTrigger\")","messagePattern":"SR\\.Format\\(SR\\.CannotChangeAfterSealed, \"DataTrigger\"\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DataTrigger.cs","lineNumber":44,"sourceCode":"        /// </summary>\n        [Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)] // Not localizable by-default\n        public BindingBase Binding\n        {\n            get\n            {\n                // Verify Context Access\n                VerifyAccess();\n\n                return _binding;\n            }\n            set\n            {\n                // Verify Context Access\n                VerifyAccess();\n\n                if (IsSealed)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"DataTrigger\"));\n                }\n\n                _binding = value;\n            }\n        }\n\n        /// <summary>\n        ///     Value of the condition (equality check)\n        /// </summary>\n        [DependsOn(\"Binding\")]\n        [Localizability(LocalizationCategory.None, Readability = Readability.Unreadable)] // Not localizable by-default\n        public object Value\n        {\n            get\n            {\n                // Verify Context Access\n                VerifyAccess();\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DataTrigger.cs#L26-L62","documentation":"The DataTrigger.Binding setter throws InvalidOperationException once the trigger has been sealed (attached to a style/template that is in use). Styles seal their triggers to keep the runtime property-engine state immutable. Modify triggers before the style is applied.","triggerScenarios":"Setting DataTrigger.Binding after the containing Style/Template has been sealed (e.g. after Style.Seal or once the style is in use by elements).","commonSituations":"Mutating shared style resources at runtime; editing triggers of a style already applied via FrameworkElement.Style; hot-reload or theming code touching live styles.","solutions":["Set Binding before assigning the style to any element or before the style is sealed","Create a new Style/DataTrigger with the desired Binding and assign it to elements","Clone or rebuild the style (new Style instance) rather than mutating the sealed one"],"exampleFix":"// before\nstyle.Triggers.Add(trigger);\nelement.Style = style;\ntrigger.Binding = new Binding(\"IsEnabled\"); // sealed -> throws\n// after\ntrigger.Binding = new Binding(\"IsEnabled\");\nstyle.Triggers.Add(trigger);\nelement.Style = style;","handlingStrategy":"validation","validationCode":"if (trigger.IsSealed) { trigger = CloneTrigger(trigger); trigger.Binding = newBinding; } else { trigger.Binding = newBinding; }","typeGuard":"bool CanModify(DataTrigger t) => !t.IsSealed;","tryCatchPattern":"try { trigger.Binding = newBinding; } catch (InvalidOperationException) { /* rebuild style/trigger */ }","preventionTips":["Configure all trigger properties before adding the style to resources/elements","Check IsSealed before mutating any Style/Trigger object","Treat applied styles as immutable; create new instances for runtime changes"],"tags":["wpf","datatrigger","sealed-style","invalid-state"],"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"}