dotnet/wpf · error · ArgumentException

SR.ConditionValueOfExpressionNotSupported

Error message

SR.ConditionValueOfExpressionNotSupported

What it means

Trigger.Value also rejects Expression instances (the base of BindingExpression-style dynamic values). Trigger conditions must be static comparable values; expressions/bindings are not supported, so ArgumentException with SR.ConditionValueOfExpressionNotSupported is thrown.

Solutions

  1. Use a DataTrigger with Binding for data-driven conditions instead of a Trigger with an Expression value.
  2. Provide a plain constant value for Trigger.Value.
  3. Evaluate the expression/binding in code and set the computed result as Value.

Example fix

// before
trigger.Value = myBinding; // throws
// after
var dataTrigger = new DataTrigger { Binding = myBinding, Value = true };
style.Triggers.Add(dataTrigger);
Defensive patterns

Strategy: type-guard

Validate before calling

if (value is Expression) throw new ArgumentException("Trigger.Value cannot be an Expression; use DataTrigger with Binding instead");

Type guard

static bool IsValidConditionValue(object v) => v is not Expression and not MarkupExtension;

Try / catch

try { trigger.Value = value; }
catch (ArgumentException) { style.Triggers.Add(new DataTrigger { Binding = binding, Value = expected }); }

Prevention

When it happens

Trigger: Assigning a Binding/Expression object (e.g. binding.Expression or a Binding instance that produced an Expression) to Trigger.Value in code.

Common situations: Developers attempting data-bound conditions on a plain Trigger instead of DataTrigger; copying Setter-like binding patterns into condition values.

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/c47a93dd001b2483. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Trigger.cs:85

                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>
        [DefaultValue(null)]
        [Ambient]
        public string SourceName
        {
            get
            {

View on GitHub (pinned to 81131a70a4)