{"record":{"id":"602cead8daf6a24a","repo":"dotnet/wpf","slug":"sr-conditionvalueofexpressionnotsupported","errorCode":null,"errorMessage":"SR.ConditionValueOfExpressionNotSupported","messagePattern":"SR\\.ConditionValueOfExpressionNotSupported","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Condition.cs","lineNumber":140,"sourceCode":"        public object Value\n        {\n            get { return _value; }\n            set\n            {\n                if (_sealed)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"Condition\"));\n                }\n\n                if (value is MarkupExtension)\n                {\n                    throw new ArgumentException(SR.Format(SR.ConditionValueOfMarkupExtensionNotSupported,\n                                                       value.GetType().Name));\n                }\n\n                if(value is Expression)\n                {\n                    throw new ArgumentException(SR.ConditionValueOfExpressionNotSupported);\n                }\n\n                _value = value;\n            }\n        }\n\n        /// <summary>\n        /// The x:Name of the object whose property shall\n        /// trigger the associated setters to be applied.\n        /// If null, then this is the object being Styled\n        /// and not anything under its Template Tree.\n        /// </summary>\n        [DefaultValue(null)]\n        public string SourceName\n        {\n            get\n            {\n                return _sourceName;","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Condition.cs#L122-L158","documentation":"Setting the Value of a WPF trigger Condition to an Expression (the result of a dynamic markup extension such as {Binding}) is not supported; conditions must have static, sealable values. The Condition class throws ArgumentException because dynamic expressions cannot be evaluated during style/trigger sealing.","triggerScenarios":"Assigning a value produced by a markup extension that returns an Expression (e.g. condition.Value = someBindingExpression) in code, or XAML where a Binding is used as the condition value.","commonSituations":"Developers try to write <Condition Property=\"IsSelected\" Value=\"{Binding ...}\" /> or set Value in code to a dynamic value, expecting triggers to re-evaluate dynamically.","solutions":["Use a static literal value for the condition Value (e.g. \"True\", a fixed enum value or color).","If dynamic behavior is needed, use a DataTrigger with a Binding in the Condition's Binding property rather than an Expression as Value.","Compute the desired value before assigning and assign the concrete result, not the expression."],"exampleFix":"// before\nnew Condition(Selector.IsSelectedProperty, someBinding.Expression);\n// after\nnew Condition(Selector.IsSelectedProperty, true);","handlingStrategy":"validation","validationCode":"if (condition.Value is Expression)\n    throw new InvalidOperationException(\"Condition.Value must be a static value, not an Expression\");","typeGuard":"bool IsValidConditionValue(object v) => v is not Expression;","tryCatchPattern":null,"preventionTips":["Never bind a trigger condition Value with {Binding}; use static literals.","Use DataTrigger Binding conditions for dynamic data-driven behavior.","Check the value with 'is Expression' before assigning in code."],"tags":["wpf","triggers","binding"],"backgroundTag":"unsupported-operation","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"}