private static void CommandProperty_Changed(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { var element = dependencyObject as FrameworkElement; if (element != null) { MouseLeftButtonDownBehavior behavior = GetOrCreateBehavior(element); behavior.Command = e.NewValue as ICommand; } }
private static MouseLeftButtonDownBehavior GetOrCreateBehavior(FrameworkElement element) { MouseLeftButtonDownBehavior behavior = element.GetValue(MouseLeftButtonDownBehaviorProperty) as MouseLeftButtonDownBehavior; if (behavior == null) { behavior = new MouseLeftButtonDownBehavior(element); element.SetValue(MouseLeftButtonDownBehaviorProperty, behavior); } return(behavior); }
public static void SetMouseLeftButtonDownBehavior(DependencyObject obj, MouseLeftButtonDownBehavior value) { obj.SetValue(MouseLeftButtonDownBehaviorProperty, value); }