Example #1
0
        protected override void OnDragOver(DragEventArgs e)
        {
            var currentPosition = e.GetPosition(WorkspaceElements);

            // create adorner if it is necessary
            if (draggedAdorner == null)
            {
                var adornerLayer = AdornerLayer.GetAdornerLayer(WorkspaceElements);
                draggedAdorner = new DraggedAdorner(draggedData,
                                                    draggedSelectionTemplate, WorkspaceElements, adornerLayer);
            }

            var zoom = ViewModel.Zoom;

            var xOffset = currentPosition.X - initialMousePosition.X;
            var yOffset = currentPosition.Y - initialMousePosition.Y;
            // compute (x; y) so that dragged selection has mouse cursor
            // in the same place as origin selection does
            var x = xOffset * zoom;
            var y = yOffset * zoom;

            // compute bounds of dragged content so that it does not go outside dragged canvas
            var x1     = -ViewModel.Model.X / zoom - xOffset;
            var y1     = -ViewModel.Model.Y / zoom - yOffset;
            var x2     = WorkspaceElements.RenderSize.Width / zoom;
            var y2     = WorkspaceElements.RenderSize.Height / zoom;
            var bounds = new Rect(x1, y1, x2, y2);

            draggedAdorner.SetPosition(x, y, bounds);
        }
Example #2
0
        public void UpdateDragDrop(DragEventArgs e)
        {
            object draggedData = e.Data.GetData(Format.Name);

            if (draggedData != null)
            {
                Point currentPosition = e.GetPosition(_topWindow);
                if (_draggedAdorner == null)
                {
                    var adornerLayer = AdornerLayer.GetAdornerLayer(_source);
                    _draggedAdorner = new DraggedAdorner(draggedData, ItemsControlBehaviors.GetDragDropTemplate(_source), _sourceItemContainer, adornerLayer);
                }
                _draggedAdorner.SetPosition(currentPosition.X - _initialMousePosition.X + _initialMouseOffset.X, currentPosition.Y - _initialMousePosition.Y + _initialMouseOffset.Y);
            }
        }
Example #3
0
        private void UpdateDraggedAdornerPos(Point currentPosition, bool makeVisible = false)
        {
            if (_draggedAdorner == null)
            {
                return;
            }

            var x = currentPosition.X - OriginalOffset.X;
            var y = currentPosition.Y - OriginalOffset.Y;

            _draggedAdorner.SetPosition(x, y);

            if (makeVisible)
            {
                ShowDraggedAdorner();
            }
        }