dotnet/wpf · error · ArgumentException

SR.ConditionValueOfExpressionNotSupported

Error message

SR.ConditionValueOfExpressionNotSupported

What it means

The DataTrigger.Value setter throws ArgumentException when the value is an Expression. Expression objects are runtime-generated (usually from markup extensions like Binding) and cannot serve as a static condition value. The condition value must be a plain literal comparable to the bound value.

Solutions

  1. Extract the underlying literal value (e.g. expression.Value or the evaluated result) before assigning
  2. Assign only primitive/CLR literal values to Value
  3. Use Binding for the dynamic side of the condition

Example fix

// before
trigger.Value = bindingExpression; // Expression -> throws
// after
trigger.Value = bindingExpression.DataItem; // or a literal value
trigger.Binding = new Binding("Amount");
Defensive patterns

Strategy: type-guard

Validate before calling

if (value is Expression) throw new ArgumentException("DataTrigger.Value cannot be an Expression", nameof(value));

Type guard

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

Try / catch

try { trigger.Value = candidate; } catch (ArgumentException) { /* evaluate the expression and assign its result */ }

Prevention

When it happens

Trigger: Assigning a value that is an Expression instance (e.g. the product of an evaluated markup extension) to DataTrigger.Value.

Common situations: Programmatically copying values from bound properties; sharing Expression objects between bindings and triggers; reflection-based tooling reassigning values verbatim.

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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/DataTrigger.cs:83

            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 Setters
        {
            get
            {
                // Verify Context Access
                VerifyAccess();

View on GitHub (pinned to 81131a70a4)