{"record":{"id":"2de299ab9b33cb2b","repo":"dotnet/wpf","slug":"sr-conditionvalueofexpressionnotsupported-datatrigger","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/DataTrigger.cs","lineNumber":83,"sourceCode":"            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                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        ///     Collection of Setter objects, which describes what to apply\n        /// when this trigger is active.\n        /// </summary>\n        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]\n        public SetterBaseCollection Setters\n        {\n            get\n            {\n                // Verify Context Access\n                VerifyAccess();\n","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DataTrigger.cs#L65-L101","documentation":"The DataTrigger.Value setter throws ArgumentException when the value is an Expression. Expression objects are runtime-generated (usually from markup extensions like Binding) and cannot serve as a static condition value. The condition value must be a plain literal comparable to the bound value.","triggerScenarios":"Assigning a value that is an Expression instance (e.g. the product of an evaluated markup extension) to DataTrigger.Value.","commonSituations":"Programmatically copying values from bound properties; sharing Expression objects between bindings and triggers; reflection-based tooling reassigning values verbatim.","solutions":["Extract the underlying literal value (e.g. expression.Value or the evaluated result) before assigning","Assign only primitive/CLR literal values to Value","Use Binding for the dynamic side of the condition"],"exampleFix":"// before\ntrigger.Value = bindingExpression; // Expression -> throws\n// after\ntrigger.Value = bindingExpression.DataItem; // or a literal value\ntrigger.Binding = new Binding(\"Amount\");","handlingStrategy":"type-guard","validationCode":"if (value is Expression) throw new ArgumentException(\"DataTrigger.Value cannot be an Expression\", nameof(value));","typeGuard":"bool IsLiteralValue(object v) => v is not Expression and not MarkupExtension;","tryCatchPattern":"try { trigger.Value = candidate; } catch (ArgumentException) { /* evaluate the expression and assign its result */ }","preventionTips":["Only assign concrete evaluated values to Value","When copying values between objects, unwrap Expression first","Unit-test trigger construction with the exact value types used at runtime"],"tags":["wpf","datatrigger","expression","argument-validation"],"backgroundTag":"invalid-argument-value","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"}