{"record":{"id":"841dc29c809e5f8d","repo":"stride3d/stride","slug":"binding-must-be-set-for-propertyname-property-of-host","errorCode":null,"errorMessage":"Binding must be set for {PropertyName} property of host '{AssociatedObject}' on behavior '{GetType().FullName}'.","messagePattern":"Binding must be set for (.+?) property of host '(.+?)' on behavior '(.+?)'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Behaviors/OnFocusBindingInterruptionBehavior.cs","lineNumber":40,"sourceCode":"        private DependencyProperty property;\n\n        /// <summary>\n        /// Gets or sets the name of the DependencyProperty on which the Binding has to be interrupted.\n        /// </summary>\n        public string PropertyName { get; set; }\n        /// <summary>\n        /// Gets or sets the binding to apply on the Host property defined by 'PropertyName' behavior property.\n        /// </summary>\n        public BindingBase Binding { get; set; }\n\n        protected override void OnAttached()\n        {\n            if (string.IsNullOrWhiteSpace(PropertyName))\n                throw new ArgumentException(\"PropertyName must be set.\");\n\n            if (Binding == null)\n            {\n                throw new ArgumentException($\"Binding must be set for {PropertyName} property of host '{AssociatedObject}' on behavior '{GetType().FullName}'.\");\n            }\n\n            property = AssociatedObject.GetDependencyProperties(true).FirstOrDefault(dp => dp.Name == PropertyName);\n\n            if (property == null /* need to check DesignMode as well ? */)\n                throw new InvalidOperationException($\"Impossible to find property named '{PropertyName}' on object typed '{AssociatedObject.GetType()}'.\");\n\n            if ((Binding is Binding) == false)\n                throw new InvalidOperationException(\"Not supported binding type.\");\n\n            var element = AssociatedObject as FrameworkElement;\n            if (element == null)\n            {\n                throw new InvalidOperationException(\n                    $\"Behavior of type '{GetType()}' must be bound to objects of type '{typeof(FrameworkElement)}'. (currently bound to object typed '{AssociatedObject.GetType()}')\");\n            }\n\n            BindingOperations.SetBinding(AssociatedObject, property, Binding);","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Behaviors/OnFocusBindingInterruptionBehavior.cs#L22-L58","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set the Binding property, e.g. Binding=\"{Binding MyViewModelValue}\" alongside PropertyName.","If using code-behind construction, assign Binding = new Binding(\"MyViewModelValue\") before the behavior attaches.","Check that the Binding attribute is not being stripped by a style, template, or Conditional compilation."],"exampleFix":"<!-- before -->\n<b:OnFocusBindingInterruptionBehavior PropertyName=\"Text\" />\n\n<!-- after -->\n<b:OnFocusBindingInterruptionBehavior PropertyName=\"Text\" Binding=\"{Binding Name, Mode=TwoWay}\" />","handlingStrategy":"validation","validationCode":"if (behavior.Binding == null)\n    throw new InvalidOperationException($\"Binding must be set for behavior {behavior.GetType().Name} before attach.\");","typeGuard":null,"tryCatchPattern":"try { AttachBehavior(behavior, host); }\ncatch (ArgumentException ex) when (ex.Message.StartsWith(\"Binding must be set\")) { log.Error($\"OnFocusBindingInterruptionBehavior on {host} lacks a Binding\"); }","preventionTips":["Never instantiate OnFocusBindingInterruptionBehavior without assigning both PropertyName and Binding.","Use a XAML code snippet that templates both attributes.","Smoke-test views in CI (render pages) so misconfigured behaviors throw during build rather than at runtime."],"tags":["wpf","behavior","binding","configuration"],"backgroundTag":"missing-required-argument","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}