dotnet/wpf · error · ArgumentException

SR.ConditionValueOfMarkupExtensionNotSupported

Error message

SR.ConditionValueOfMarkupExtensionNotSupported

What it means

Condition.Value does not accept a MarkupExtension (e.g. StaticResource, Binding) — the trigger evaluation engine needs an actual evaluated value, not deferred markup. Assigning one throws ArgumentException (ConditionValueOfMarkupExtensionNotSupported) with the extension type name.

Solutions

  1. Resolve the markup extension first (e.g. FindResource for StaticResource) and assign the actual value
  2. Assign the concrete CLR/enum value matching the property type
  3. Never pass Binding/StaticResource/DynamicResource extension objects to Condition.Value

Example fix

// before
condition.Value = new StaticResourceExtension("MyBrush"); // throws
// after
condition.Value = element.FindResource("MyBrush");
Defensive patterns

Strategy: validation

Validate before calling

if (value is MarkupExtension ext) value = ResolveExtension(ext); // e.g. FindResource for StaticResourceExtension
if (value is Expression) throw new ArgumentException("Expressions are not valid Condition values");

Type guard

bool IsDeferredValue(object v) => v is MarkupExtension or Expression; // reject these before assigning

Try / catch

try { condition.Value = v; } catch (ArgumentException ex) when (ex.Message.Contains("MarkupExtension")) { /* resolve resource and retry */ }

Prevention

When it happens

Trigger: Setting Condition.Value to a MarkupExtension instance, typically when building conditions in code with resource lookups instead of resolved values.

Common situations: Porting XAML trigger values to C# and copying the markup extension object instead of its evaluated result; using FindResource/StaticResource incorrectly.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/ebe9636db74f183f. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Condition.cs:134

        }

        /// <summary>
        ///     Value of the condition (equality check)
        /// </summary>
        [TypeConverter(typeof(System.Windows.Markup.SetterTriggerConditionValueConverter))]
        public object Value
        {
            get { return _value; }
            set
            {
                if (_sealed)
                {
                    throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, "Condition"));
                }

                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)