private static void CommandProperty_Changed(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { Control element = dependencyObject as Control; if (element != null) { KeyDownBehavior behavior = GetOrCreateBehavior(element); behavior.Command = e.NewValue as ICommand; } }
private static KeyDownBehavior GetOrCreateBehavior(Control element) { KeyDownBehavior behavior = element.GetValue(KeyDownBehaviorProperty) as KeyDownBehavior; if (behavior == null) { behavior = new KeyDownBehavior(element); element.SetValue(KeyDownBehaviorProperty, behavior); } return(behavior); }
public static void SetKeyDownBehavior(DependencyObject obj, KeyDownBehavior value) { obj.SetValue(KeyDownBehaviorProperty, value); }