private static void ElementMouseDown(object sender, MouseButtonEventArgs e) { DragMouseButton dragMouseButton = (DragMouseButton)((DependencyObject)sender).GetValue(Advent.Common.UI.DragDrop.DragMouseButtonProperty); if (dragMouseButton == DragMouseButton.None || e.ChangedButton != (MouseButton)dragMouseButton || e.ButtonState != MouseButtonState.Pressed) { return; } Advent.Common.UI.DragDrop.isDragging = true; Advent.Common.UI.DragDrop.dragPoint = e.GetPosition((IInputElement)sender); }
private static void OnDragMouseButtonChanged(DependencyObject obj, DependencyPropertyChangedEventArgs args) { UIElement uiElement = (UIElement)obj; DragMouseButton dragMouseButton = (DragMouseButton)args.NewValue; if ((DragMouseButton)args.OldValue == DragMouseButton.None) { uiElement.MouseDown += new MouseButtonEventHandler(Advent.Common.UI.DragDrop.ElementMouseDown); uiElement.MouseMove += new MouseEventHandler(Advent.Common.UI.DragDrop.ElementMouseMove); uiElement.MouseUp += new MouseButtonEventHandler(Advent.Common.UI.DragDrop.ElementMouseUp); } else { if (dragMouseButton != DragMouseButton.None) { return; } uiElement.MouseDown -= new MouseButtonEventHandler(Advent.Common.UI.DragDrop.ElementMouseDown); uiElement.MouseMove -= new MouseEventHandler(Advent.Common.UI.DragDrop.ElementMouseMove); uiElement.MouseUp -= new MouseButtonEventHandler(Advent.Common.UI.DragDrop.ElementMouseUp); } }
public static void SetDragMouseButton(DependencyObject element, DragMouseButton button) { element.SetValue(Advent.Common.UI.DragDrop.DragMouseButtonProperty, (object)button); }