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