private static void ElementMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { var element = (UIElement)sender; // find the ReoderListBox parent of the element var reorderListBox = TreeHelpers.FindParent <ReorderListBox>(element); if (reorderListBox != null) { // find the ItemContainer FrameworkElement f = TreeHelpers.GetItemContainerFromChildElement(reorderListBox, element) as FrameworkElement; if (f != null) { reorderListBox.BeginDrag(f); } } }
protected override void OnMouseMove(MouseEventArgs e) { if (_isDragging && _dragAdorner != null) { // update the position of the adorner var current = e.GetPosition(this); _dragAdorner.OffsetX = current.X - _mouseDown.X; _dragAdorner.OffsetY = current.Y - _mouseDown.Y; // find the item that we are dragging over var element = InputHitTest(new Point(e.GetPosition(this).X, e.GetPosition(this).Y)) as UIElement; if (element != null) { var itemOver = TreeHelpers.GetItemContainerFromChildElement(this, element) as FrameworkElement; if (itemOver != null) { var p = Mouse.GetPosition(itemOver); var q = PointToQuadrant(itemOver, p); if (itemOver != _lastMouseOverItem || q != _lastMouseOverQuadrant) { if (q == ReorderQuadrant.BottomLeft || q == ReorderQuadrant.BottomRight) { _lastMoveOverPlacement = ReorderPlacement.After; } else { _lastMoveOverPlacement = ReorderPlacement.Before; } PreviewInsert(itemOver, _lastMoveOverPlacement); _lastMouseOverItem = itemOver; _lastMouseOverQuadrant = q; } } } } base.OnMouseMove(e); }