{"record":{"id":"354be89c75737766","repo":"dotnet/wpf","slug":"sr-format-sr-conditionvalueofmarkupextensionnotsupported","errorCode":null,"errorMessage":"SR.Format(SR.ConditionValueOfMarkupExtensionNotSupported, value.GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.ConditionValueOfMarkupExtensionNotSupported, value\\.GetType\\(\\)\\.Name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DataTrigger.cs","lineNumber":77,"sourceCode":"            {\n                // Verify Context Access\n                VerifyAccess();\n\n                return _value;\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                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","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DataTrigger.cs#L59-L95","documentation":"The DataTrigger.Value setter rejects MarkupExtension instances with ArgumentException. Markup extensions (like Binding or StaticResource) are deferred values that the condition system cannot evaluate as a literal comparison value. Use Binding on the trigger for dynamic conditions and keep Value a literal.","triggerScenarios":"Assigning e.g. trigger.Value = new Binding(...) or another MarkupExtension-derived object to DataTrigger.Value.","commonSituations":"Copy-pasting XAML semantics into code (thinking Value can be a binding); attempting dynamic condition values instead of using the trigger's Binding.","solutions":["Put the dynamic part in DataTrigger.Binding and compare against a literal Value","Use a plain CLR value (string, number, enum) for Value","If deferred lookup is needed, resolve the resource to a concrete value before assignment"],"exampleFix":"// before\ntrigger.Value = new Binding(\"Threshold\"); // throws\n// after\ntrigger.Binding = new Binding(\"Amount\");\ntrigger.Value = 100;","handlingStrategy":"type-guard","validationCode":"if (value is MarkupExtension) throw new ArgumentException(\"DataTrigger.Value cannot be a MarkupExtension; use Binding instead\", nameof(value));","typeGuard":"bool IsValidTriggerValue(object v) => v is not MarkupExtension;","tryCatchPattern":"try { trigger.Value = candidate; } catch (ArgumentException) { /* move dynamic logic to trigger.Binding */ }","preventionTips":["Keep Value literal (string/number/enum); put dynamics in Binding","Do not copy MarkupExtension results into Value","Sanitize values arriving from config/reflection before assignment"],"tags":["wpf","datatrigger","markup-extension","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"}