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