Exemple #1
0
        static void DragSource_PreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (_mDragInfo == null && _mBolPreviewMouseLeftButtonDown)
            {
                _mBolPreviewMouseLeftButtonDown = false;
                if (HitTestScrollBar(sender, e))
                {
                    _mDragInfo = null;
                    return;
                }
                _mDragInfo = new DragInfo(sender, e);
                IDragSource dragHandler = GetDragHandler(_mDragInfo.VisualSource);

                if (dragHandler != null)
                {
                    _mDragInfo.Data = dragHandler.DragData();
                }
            }

            if (_mDragInfo != null)
            {
                Point dragStart = _mDragInfo.DragStartPosition;
                Point position  = e.GetPosition(null);

                if (Math.Abs(position.X - dragStart.X) > SystemParameters.MinimumHorizontalDragDistance ||
                    Math.Abs(position.Y - dragStart.Y) > SystemParameters.MinimumVerticalDragDistance)
                {
                    var dragHandler = GetDragHandler(_mDragInfo.VisualSource);

                    if (dragHandler != null)
                    {
                        _mDragInfo.Effects = dragHandler.StartDrag(_mDragInfo.Data);

                        if (_mDragInfo.Effects != DragDropEffects.None && _mDragInfo.Data != null)
                        {
                            var data = new DataObject(MFormat.Name, _mDragInfo.Data);
                            System.Windows.DragDrop.DoDragDrop(_mDragInfo.VisualSource, data, _mDragInfo.Effects);
                            _mDragInfo = null;
                        }
                    }
                }
            }
        }