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); }
private void PreviewInsert(FrameworkElement relativeTo, ReorderPlacement placement) { if (_isDragging && _dragItem != null && relativeTo != null) { // get the index of the item being dragged var relativeToIndex = ItemContainerGenerator.IndexFromContainer(relativeTo); // get the index of insertion var offset = (placement == ReorderPlacement.Before) ? 0 : 1; _dragInsertIndex = relativeToIndex + offset; for (int i = 0; i < Items.Count; i++) { double delta; if (i > _dragItemIndex && i < _dragInsertIndex) { delta = -1 * GetOrientedDimension(_dragItem); } else if (i < _dragItemIndex && i >= _dragInsertIndex) { delta = GetOrientedDimension(_dragItem); } else { delta = 0; } TranslateItem((FrameworkElement)ItemContainerGenerator.ContainerFromIndex(i), delta, this.Duration, Orientation); } // if the insert location is after the current location, we need to decrement it // by one after we've made the visual adjustments so that the actual drop index // will be accurate if (_dragInsertIndex > _dragItemIndex) { _dragInsertIndex--; } } }
private void PreviewInsert(FrameworkElement relativeTo, ReorderPlacement placement) { if (m_isDragging && m_dragItem != null && relativeTo != null) { // get the index of the item being dragged int relativeToIndex = ItemContainerGenerator.IndexFromContainer(relativeTo); // get the index of insertion var offset = (placement == ReorderPlacement.Before) ? 0 : 1; m_dragInsertIndex = relativeToIndex + offset; for (int i = 0; i < Items.Count; i++) { if (i > m_dragItemIndex && i < m_dragInsertIndex) { TranslateItem(ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement, (m_dragItem.ActualHeight * -1)); } else if (i < m_dragItemIndex && i >= m_dragInsertIndex) { TranslateItem(ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement, (m_dragItem.ActualHeight)); } else { TranslateItem(ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement, 0); } } // if the insert location is after the current location, we need to decrement it // by one after we've made the visual adjustments so that the actual drop index // will be accurate if (m_dragInsertIndex > m_dragItemIndex) { m_dragInsertIndex--; } } }
private void PreviewInsert(FrameworkElement relativeTo, ReorderPlacement placement) { if (m_isDragging && m_dragItem != null && relativeTo != null) { // get the index of the item being dragged int relativeToIndex = ItemContainerGenerator.IndexFromContainer(relativeTo); // get the index of insertion var offset = (placement == ReorderPlacement.Before) ? 0 : 1; m_dragInsertIndex = relativeToIndex + offset; for (int i = 0; i < Items.Count; i++) { if (i > m_dragItemIndex && i < m_dragInsertIndex) { TranslateItem(ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement, (m_dragItem.ActualHeight * -1)); } else if (i < m_dragItemIndex && i >= m_dragInsertIndex) { TranslateItem(ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement, (m_dragItem.ActualHeight)); } else { TranslateItem(ItemContainerGenerator.ContainerFromIndex(i) as FrameworkElement, 0); } } // if the insert location is after the current location, we need to decrement it // by one after we've made the visual adjustments so that the actual drop index // will be accurate if (m_dragInsertIndex > m_dragItemIndex) m_dragInsertIndex--; } }
protected override void OnMouseMove(MouseEventArgs e) { if (m_isDragging && m_dragAdorner != null) { // update the position of the adorner Point current = e.GetPosition(this); m_dragAdorner.OffsetY = current.Y - m_mouseDown.Y; // find the item that we are dragging over UIElement element = this.InputHitTest(new Point(this.ActualWidth / 2, e.GetPosition(this).Y)) as UIElement; if (element != null) { FrameworkElement itemOver = TreeHelpers.GetItemContainerFromChildElement(this, element) as FrameworkElement; if (itemOver != null) { Point p = Mouse.GetPosition(itemOver); ReorderQuadrant q = PointToQuadrant(itemOver, p); if (itemOver != m_lastMouseOverItem || q != m_lastMouseOverQuadrant) { if (q == ReorderQuadrant.BottomLeft || q == ReorderQuadrant.BottomRight) { m_lastMoveOverPlacement = ReorderPlacement.After; } else { m_lastMoveOverPlacement = ReorderPlacement.Before; } PreviewInsert(itemOver, m_lastMoveOverPlacement); m_lastMouseOverItem = itemOver; m_lastMouseOverQuadrant = q; } } } } base.OnMouseMove(e); }
private void PreviewInsert(FrameworkElement relativeTo, ReorderPlacement placement) { if (m_isDragging && m_dragItem != null && relativeTo != null) { // get the index of the item being dragged var relativeToIndex = ItemContainerGenerator.IndexFromContainer(relativeTo); // get the index of insertion var offset = (placement == ReorderPlacement.Before) ? 0 : 1; m_dragInsertIndex = relativeToIndex + offset; for (int i = 0; i < Items.Count; i++) { double delta; if (i > m_dragItemIndex && i < m_dragInsertIndex) { delta = -1 * getOrientedDimension(m_dragItem); } else if (i < m_dragItemIndex && i >= m_dragInsertIndex) { delta = getOrientedDimension(m_dragItem); } else { delta = 0; } TranslateItem((FrameworkElement)ItemContainerGenerator.ContainerFromIndex(i), delta, this.Duration, Orientation); } // if the insert location is after the current location, we need to decrement it // by one after we've made the visual adjustments so that the actual drop index // will be accurate if (m_dragInsertIndex > m_dragItemIndex) { m_dragInsertIndex--; } } }