Exemple #1
0
        private bool IsMouseOver(Visual target)
        {
            var descendantBounds = VisualTreeHelper.GetDescendantBounds(target);
            var mousePosition    = MouseUtilities.GetMousePosition(target);

            return(descendantBounds.Contains(mousePosition));
        }
        private void OnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (IsMouseOverScrollbar)
            {
                _canInitiateDrag = false;
            }
            else
            {
                int index = GetIndexUnderDragCursor();
                _canInitiateDrag = index > -1;

                if (_canInitiateDrag)
                {
                    _mouseDownPosition = MouseUtilities.GetMousePosition(_listView);
                    _indexToSelect     = index;

                    ConfigureAllowDropToItems(index);
                }
                else
                {
                    _mouseDownPosition = new Point(-10000, -10000);
                    _indexToSelect     = -1;
                }
            }
        }
Exemple #3
0
        private AdornerLayer InitializeAdornerLayer(ListViewItem itemToDrag)
        {
            var brush = new VisualBrush(itemToDrag);

            _dragAdornerLayer         = new DragAdornerLayer(this._listView, itemToDrag.RenderSize, brush);
            _dragAdornerLayer.Opacity = _dragAdornerLayerOpacity;

            var adornerLayer = AdornerLayer.GetAdornerLayer(_listView);

            adornerLayer.Add(_dragAdornerLayer);
            _mouseDownPosition = MouseUtilities.GetMousePosition(_listView);

            return(adornerLayer);
        }
Exemple #4
0
        private void UpdateDragAdornerLocation()
        {
            if (_dragAdornerLayer != null)
            {
                var mousePosition = MouseUtilities.GetMousePosition(_listView);

                double left = mousePosition.X - this._mouseDownPosition.X;

                var    itemBeingDragged = _listView.GetListViewItem(_indexToSelect);
                var    itemLoc          = itemBeingDragged.TranslatePoint(new Point(0, 0), _listView);
                double top = itemLoc.Y + mousePosition.Y - _mouseDownPosition.Y;

                _dragAdornerLayer.SetOffsets(left, top);
            }
        }