stride3d/stride · error · ArgumentException

Binding must be set for

Error message

Binding must be set for {PropertyName} property of host '{AssociatedObject}' on behavior '{GetType().FullName}'.

What it means

After validating PropertyName, OnFocusBindingInterruptionBehavior requires a Binding (of type BindingBase) to apply when focus interrupts the existing binding. If the Binding property is null when the behavior attaches, it throws ArgumentException naming the property, host element, and behavior type so the misconfiguration is easy to locate.

Solutions

  1. Set the Binding property, e.g. Binding="{Binding MyViewModelValue}" alongside PropertyName.
  2. If using code-behind construction, assign Binding = new Binding("MyViewModelValue") before the behavior attaches.
  3. Check that the Binding attribute is not being stripped by a style, template, or Conditional compilation.

Example fix

<!-- before -->
<b:OnFocusBindingInterruptionBehavior PropertyName="Text" />

<!-- after -->
<b:OnFocusBindingInterruptionBehavior PropertyName="Text" Binding="{Binding Name, Mode=TwoWay}" />
Defensive patterns

Strategy: validation

Validate before calling

if (behavior.Binding == null)
    throw new InvalidOperationException($"Binding must be set for behavior {behavior.GetType().Name} before attach.");

Try / catch

try { AttachBehavior(behavior, host); }
catch (ArgumentException ex) when (ex.Message.StartsWith("Binding must be set")) { log.Error($"OnFocusBindingInterruptionBehavior on {host} lacks a Binding"); }

Prevention

When it happens

Trigger: Attaching OnFocusBindingInterruptionBehavior with PropertyName set but no Binding assigned, e.g. <b:OnFocusBindingInterruptionBehavior PropertyName="Text"/> without a Binding attribute, or Binding set to a binding that fails to initialize to a non-null BindingBase instance.

Common situations: Partial copy-paste of XAML where the Binding attribute was dropped; using a style/trigger that sets PropertyName but forgets Binding; constructing the behavior in code with `new OnFocusBindingInterruptionBehavior { PropertyName = "Text" }` and forgetting Binding.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/841dc29c809e5f8d. Report an issue: GitHub.

Appendix: source

Thrown at sources/presentation/Stride.Core.Presentation.Wpf/Behaviors/OnFocusBindingInterruptionBehavior.cs:40

        private DependencyProperty property;

        /// <summary>
        /// Gets or sets the name of the DependencyProperty on which the Binding has to be interrupted.
        /// </summary>
        public string PropertyName { get; set; }
        /// <summary>
        /// Gets or sets the binding to apply on the Host property defined by 'PropertyName' behavior property.
        /// </summary>
        public BindingBase Binding { get; set; }

        protected override void OnAttached()
        {
            if (string.IsNullOrWhiteSpace(PropertyName))
                throw new ArgumentException("PropertyName must be set.");

            if (Binding == null)
            {
                throw new ArgumentException($"Binding must be set for {PropertyName} property of host '{AssociatedObject}' on behavior '{GetType().FullName}'.");
            }

            property = AssociatedObject.GetDependencyProperties(true).FirstOrDefault(dp => dp.Name == PropertyName);

            if (property == null /* need to check DesignMode as well ? */)
                throw new InvalidOperationException($"Impossible to find property named '{PropertyName}' on object typed '{AssociatedObject.GetType()}'.");

            if ((Binding is Binding) == false)
                throw new InvalidOperationException("Not supported binding type.");

            var element = AssociatedObject as FrameworkElement;
            if (element == null)
            {
                throw new InvalidOperationException(
                    $"Behavior of type '{GetType()}' must be bound to objects of type '{typeof(FrameworkElement)}'. (currently bound to object typed '{AssociatedObject.GetType()}')");
            }

            BindingOperations.SetBinding(AssociatedObject, property, Binding);

View on GitHub (pinned to 96fad776d2)