dotnet/wpf · error · ArgumentException
SR.Format(SR.ConditionValueOfMarkupExtensionNotSupported…
Error message
SR.Format(SR.ConditionValueOfMarkupExtensionNotSupported, value.GetType().Name)
What it means
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.
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
Example fix
// before
trigger.Value = new Binding("Threshold"); // throws
// after
trigger.Binding = new Binding("Amount");
trigger.Value = 100; Defensive patterns
Strategy: type-guard
Validate before calling
if (value is MarkupExtension) throw new ArgumentException("DataTrigger.Value cannot be a MarkupExtension; use Binding instead", nameof(value)); Type guard
bool IsValidTriggerValue(object v) => v is not MarkupExtension;
Try / catch
try { trigger.Value = candidate; } catch (ArgumentException) { /* move dynamic logic to trigger.Binding */ } Prevention
- 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
When it happens
Trigger: Assigning e.g. trigger.Value = new Binding(...) or another MarkupExtension-derived object to DataTrigger.Value.
Common situations: Copy-pasting XAML semantics into code (thinking Value can be a binding); attempting dynamic condition values instead of using the trigger's Binding.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.ConditionValueOfExpressionNotSupported
- ' ' is not a valid value for ' '.
- ArgumentException(message, name)
- ArgumentNullException(name)
- ArgumentOutOfRangeException(authentication)
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/354be89c75737766.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DataTrigger.cs:77
{
// Verify Context Access
VerifyAccess();
return _value;
}
set
{
// Verify Context Access
VerifyAccess();
if (IsSealed)
{
throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, "DataTrigger"));
}
if (value is MarkupExtension)
{
throw new ArgumentException(SR.Format(SR.ConditionValueOfMarkupExtensionNotSupported,
value.GetType().Name));
}
if( value is Expression )
{
throw new ArgumentException(SR.ConditionValueOfExpressionNotSupported);
}
_value = value;
}
}
/// <summary>
/// Collection of Setter objects, which describes what to apply
/// when this trigger is active.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public SetterBaseCollection SettersView on GitHub (pinned to 81131a70a4)