static void OnCommandOnTextChangedChanged(DependencyObject source, DependencyPropertyChangedEventArgs args) { TextBox sender = (TextBox)source; var command = GetTextboxCommand(sender); if (command != null) { command.Detach(); SetTextboxCommand(sender, null); } if (args.NewValue != null) { command = new TextboxCommand() { TextBox = sender, Command = (ICommand)args.NewValue }; command.Attach(); SetTextboxCommand(sender, command); } }
static void SetTextboxCommand(DependencyObject obj, TextboxCommand value) { obj.SetValue(TextboxCommandProperty, value); }