dotnet/wpf · error · ArgumentException
SR.Format(SR.ConditionValueOfMarkupExtensionNotSupported…
Error message
SR.Format(SR.ConditionValueOfMarkupExtensionNotSupported, value.GetType().Name)
What it means
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.
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.
Example fix
// before
trigger.Value = new StaticResourceExtension("MyBrush"); // throws
// after
trigger.Value = someWindow.FindResource("MyBrush"); Defensive patterns
Strategy: type-guard
Validate before calling
if (value is MarkupExtension) throw new ArgumentException("Trigger.Value cannot be a MarkupExtension; use a literal value or DataTrigger"); Type guard
static bool IsValidConditionValue(object v) => v is not MarkupExtension;
Try / catch
try { trigger.Value = value; }
catch (ArgumentException ex) { log.Error(ex.Message); trigger.Value = ResolveLiteral(value); } Prevention
- Never assign StaticResource/DynamicResource extensions directly to Trigger.Value in code
- Resolve resources with FindResource before assigning
- Use DataTrigger.Binding for data-dependent conditions
When it happens
Trigger: 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.
Common situations: Trying to use Binding or DynamicResource as a trigger condition value; confusing triggers (value-based, no binding) with DataTriggers on bindings.
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
- SR.Format(SR.UnexpectedParameterType, o.GetType()…
- ArgumentOutOfRangeException (timeout was Duration.Automatic)
- Collection_BadRank
- Collection_CopyTo_ArrayCannotBeMultidimensional
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ebf2017377271aa5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs:79
}
set
{
// Verify Context Access
VerifyAccess();
if (IsSealed)
{
throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, "Trigger"));
}
if (value is NullExtension)
{
value = null;
}
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>
/// The x:Name of the object whose property shall
/// trigger the associated setters to be applied.
/// If null, then this is the object being Styled
/// and not anything under its Template Tree.
/// </summary>View on GitHub (pinned to 81131a70a4)