private static void OnSetCommandCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { TextBox textBox = dependencyObject as TextBox; if (textBox != null) { TextBoxCommandBehavior behavior = GetOrCreateBehavior(textBox); behavior.Command = e.NewValue as ICommand; } }
private static TextBoxCommandBehavior GetOrCreateBehavior(TextBox textBox) { TextBoxCommandBehavior behavior = textBox.GetValue(KeyUpCommandBehaviorProperty) as TextBoxCommandBehavior; if (behavior == null) { behavior = new TextBoxCommandBehavior(textBox); textBox.SetValue(KeyUpCommandBehaviorProperty, behavior); } return(behavior); }