{"record":{"id":"ebf2017377271aa5","repo":"dotnet/wpf","slug":"sr-format-sr-conditionvalueofmarkupextensionnotsupported-ebf201","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/Trigger.cs","lineNumber":79,"sourceCode":"            }\n            set\n            {\n                // Verify Context Access\n                VerifyAccess();\n\n                if (IsSealed)\n                {\n                    throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"Trigger\"));\n                }\n\n                if (value is NullExtension)\n                {\n                    value = null;\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>","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs#L61-L97","documentation":"Trigger.Value cannot be a MarkupExtension; trigger conditions are compared against a literal value, and extensions are resolved at XAML load time as values, not as condition operands. Setting a MarkupExtension instance as the value throws ArgumentException naming the extension type.","triggerScenarios":"In code: trigger.Value = new StaticResourceExtension(...) or new Binding() on a Trigger (as opposed to MultiTrigger.Condition). In XAML this is blocked earlier by the parser.","commonSituations":"Trying to use Binding or DynamicResource as a trigger condition value; confusing triggers (value-based, no binding) with DataTriggers on bindings.","solutions":["Use a literal value for Trigger.Value (e.g. true, a color, an enum constant).","If the condition depends on data, use a DataTrigger whose Binding does the comparison instead of a MarkupExtension value.","For resource-based values, resolve the resource first (FindResource) and assign the resolved object."],"exampleFix":"// before\ntrigger.Value = new StaticResourceExtension(\"MyBrush\"); // throws\n// after\ntrigger.Value = someWindow.FindResource(\"MyBrush\");","handlingStrategy":"type-guard","validationCode":"if (value is MarkupExtension) throw new ArgumentException(\"Trigger.Value cannot be a MarkupExtension; use a literal value or DataTrigger\");","typeGuard":"static bool IsValidConditionValue(object v) => v is not MarkupExtension;","tryCatchPattern":"try { trigger.Value = value; }\ncatch (ArgumentException ex) { log.Error(ex.Message); trigger.Value = ResolveLiteral(value); }","preventionTips":["Never assign StaticResource/DynamicResource extensions directly to Trigger.Value in code","Resolve resources with FindResource before assigning","Use DataTrigger.Binding for data-dependent conditions"],"tags":["wpf","trigger","markup-extension","argument-exception"],"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"}