{"record":{"id":"6f8be13beb6f9886","repo":"stride3d/stride","slug":"the-propertyname-property-must-be-set-on-behavior-gettype","errorCode":null,"errorMessage":"The PropertyName property must be set on behavior '{GetType().FullName}'.","messagePattern":"The PropertyName property must be set on behavior '(.+?)'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/Behaviors/OnPropertyChangedCommandBehavior.cs","lineNumber":76,"sourceCode":"        /// Gets or sets the parameter of the command to execute when the property is modified.\n        /// </summary>\n        public object CommandParameter { get { return GetValue(CommandParameterProperty); } set { SetValue(CommandParameterProperty, value); } }\n\n        /// <summary>\n        /// Gets or set whether the command should be executed only when the source of the binding associated to the dependency property is updated.\n        /// </summary>\n        /// <remarks>If set to <c>true</c>, this property requires that a binding exists on the dependency property and that it has <see cref=\"Binding.NotifyOnSourceUpdated\"/> set to <c>true</c>.</remarks>\n        public bool ExecuteOnlyOnSourceUpdate { get { return (bool)GetValue(ExecuteOnlyOnSourceUpdateProperty); } set { SetValue(ExecuteOnlyOnSourceUpdateProperty, value.Box()); } }\n        \n        /// <summary>\n        /// Gets or sets whether the value of the property should be used as the parameter of the command to execute when the property is modified.\n        /// </summary>\n        public bool PassValueAsParameter { get { return (bool)GetValue(PassValueAsParameterProperty); } set { SetValue(PassValueAsParameterProperty, value.Box()); } }\n\n        protected override void OnAttached()\n        {\n            if (PropertyName == null)\n                throw new ArgumentException($\"The PropertyName property must be set on behavior '{GetType().FullName}'.\");\n\n            dependencyProperty = AssociatedObject.GetDependencyProperties(true).FirstOrDefault(dp => dp.Name == PropertyName);\n            if (dependencyProperty == null)\n                throw new ArgumentException($\"Unable to find property '{PropertyName}' on object of type '{AssociatedObject.GetType().FullName}'.\");\n\n            propertyWatcher.Attach(AssociatedObject);\n            // TODO: Register/Unregister handlers when the PropertyName changes\n            propertyWatcher.RegisterValueChangedHandler(dependencyProperty, OnPropertyChanged);\n            Binding.AddSourceUpdatedHandler(AssociatedObject, OnSourceUpdated);\n        }\n\n        protected override void OnDetaching()\n        {\n            propertyWatcher.Detach();\n            base.OnDetaching();\n        }\n\n        private void OnSourceUpdated(object sender, [NotNull] DataTransferEventArgs e)","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/Behaviors/OnPropertyChangedCommandBehavior.cs#L58-L94","documentation":"OnPropertyChangedCommandBehavior watches a named dependency property on the associated object and invokes a Command whenever it changes. OnAttached first requires PropertyName to be non-null; if it was never set, it throws ArgumentException naming the behavior type. Note it checks only for null, not empty strings.","triggerScenarios":"Using <b:OnPropertyChangedCommandBehavior Command=\"{Binding MyCommand}\"/> without a PropertyName attribute; constructing the behavior in code without assigning PropertyName; a bound/templated value for PropertyName that is null at attach time.","commonSituations":"Copy-pasting behavior XAML and deleting the PropertyName attribute; wiring the behavior through a style where only Command is set; dynamic configuration where PropertyName comes from a ViewModel property that isn't populated yet when the element loads.","solutions":["Set PropertyName on the behavior to the dependency property to watch, e.g. PropertyName=\"IsChecked\".","If configured in code, assign PropertyName before attaching the behavior to the element.","If PropertyName comes from data, ensure it is available at attach time or set it directly in XAML."],"exampleFix":"<!-- before -->\n<CheckBox IsChecked=\"{Binding Enabled}\">\n  <i:Interaction.Behaviors>\n    <b:OnPropertyChangedCommandBehavior Command=\"{Binding EnabledChanged}\" />\n  </i:Interaction.Behaviors>\n</CheckBox>\n\n<!-- after -->\n<CheckBox IsChecked=\"{Binding Enabled}\">\n  <i:Interaction.Behaviors>\n    <b:OnPropertyChangedCommandBehavior PropertyName=\"IsChecked\" Command=\"{Binding EnabledChanged}\" />\n  </i:Interaction.Behaviors>\n</CheckBox>","handlingStrategy":"validation","validationCode":"if (behavior.PropertyName == null)\n    throw new InvalidOperationException(\"OnPropertyChangedCommandBehavior requires PropertyName before attach.\");","typeGuard":null,"tryCatchPattern":"try { AttachBehavior(behavior, host); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"The PropertyName property must be set\")) { log.Error(\"Behavior misconfigured: PropertyName is null\"); }","preventionTips":["Always set PropertyName alongside Command when using OnPropertyChangedCommandBehavior.","Avoid supplying PropertyName via late-binding data; hard-code it in XAML where possible.","Add a unit/UI test that instantiates key views to catch attach-time argument errors early."],"tags":["wpf","behavior","configuration","argument"],"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"}