{"record":{"id":"7273350b8fb3ef79","repo":"dotnet/wpf","slug":"sr-cannotchangeaftersealed","errorCode":null,"errorMessage":"SR.CannotChangeAfterSealed","messagePattern":"SR\\.CannotChangeAfterSealed","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Condition.cs","lineNumber":83,"sourceCode":"            ArgumentNullException.ThrowIfNull(binding);\n\n            Binding = binding;\n            Value  = conditionValue;\n        }\n\n        /// <summary>\n        ///     DepedencyProperty of the conditional\n        /// </summary>\n        [Ambient]\n        [DefaultValue(null)]\n        public DependencyProperty Property\n        {\n            get { return _property; }\n            set\n            {\n                if (_sealed)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"Condition\"));\n                }\n\n                if (_binding != null)\n                {\n                    throw new InvalidOperationException(SR.ConditionCannotUseBothPropertyAndBinding);\n                }\n\n                _property = value;\n            }\n        }\n\n        /// <summary>\n        ///     Binding of the conditional\n        /// </summary>\n        [DefaultValue(null)]\n        public BindingBase Binding\n        {\n            get { return _binding; }","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Condition.cs#L65-L101","documentation":"Condition.Property cannot be modified after the Condition has been sealed. Conditions are sealed when their owning Trigger/Style is applied/sealed, so changing Property afterwards throws InvalidOperationException (CannotChangeAfterSealed).","triggerScenarios":"Setting the Property property of a Condition that belongs to a trigger already sealed by an applied Style/Template.","commonSituations":"Mutating trigger conditions at runtime after the style was applied; reusing a cached trigger object across styles and trying to reconfigure it.","solutions":["Create a new Condition (and new Trigger) instead of mutating a sealed one","Modify conditions only before the Style/Trigger is sealed (before ApplyTemplate/Style application)","Rebuild the whole Style and re-apply it if dynamic behavior is needed"],"exampleFix":"// before\nsealedCondition.Property = SomeProperty; // throws\n// after\nvar condition = new Condition(SomeProperty, value);\ntrigger.Conditions.Add(condition);","handlingStrategy":"validation","validationCode":"// Only mutate conditions before the owning Style/Trigger is applied; else recreate\nvar condition = new Condition(newProperty, conditionValue);\ntrigger.Conditions.Add(condition);","typeGuard":null,"tryCatchPattern":"try { condition.Property = p; } catch (InvalidOperationException) { /* recreate condition + trigger */ }","preventionTips":["Configure triggers fully before applying the Style","Rebuild Style/Trigger objects for runtime changes","Don't cache and mutate trigger instances after use"],"tags":["wpf","triggers","sealed","invalid-operation"],"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-22T01:17:13.364Z"}