private static void MiddleClickCommand_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { var Element = o as FrameworkElement; if (Element == null) { throw new ArgumentException("Type mismatch", "o"); } var Value = (ICommand)e.NewValue; var Listener = GetMiddleClickCommandWeakEventListener(Element); if (Value != null) { if (Listener == null) { Listener = new MiddleClickCommandEventListener(); } SetMiddleClickCommandWeakEventListener(Element, Listener); PreviewMouseDownEventManager.AddListener(Element, Listener); } else if (Listener != null) { SetMiddleClickCommandWeakEventListener(Element, null); PreviewMouseDownEventManager.RemoveListener(Element, Listener); } }
private static void DoDragMove_PropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { var Element = o as FrameworkElement; if (Element == null) { throw new ArgumentException("Type mismatch", "o"); } var Value = (bool)e.NewValue; var DownListener = GetDoDragMoveMouseDownWeakEventListenerProperty(Element); var MoveListener = GetDoDragMoveMouseMoveWeakEventListenerProperty(Element); if (Value) { if (MoveListener == null) { MoveListener = new DoDragMoveMouseMoveEventListener(); } if (DownListener == null) { DownListener = new DoDragMoveMouseDownEventListener(); } SetDoDragMoveMouseMoveWeakEventListenerProperty(Element, MoveListener); SetDoDragMoveMouseDownWeakEventListenerProperty(Element, DownListener); PreviewMouseMoveEventManager.AddListener(Element, MoveListener); PreviewMouseDownEventManager.AddListener(Element, DownListener); } else { if (MoveListener != null) { SetDoDragMoveMouseMoveWeakEventListenerProperty(Element, null); PreviewMouseMoveEventManager.RemoveListener(Element, MoveListener); } if (DownListener != null) { SetDoDragMoveMouseDownWeakEventListenerProperty(Element, null); PreviewMouseDownEventManager.RemoveListener(Element, DownListener); } } }