Пример #1
0
        private void HandleDragDelta(object sender, DragContainerEventArgs e)
        {
            // Don't actually start the drag unless the mouse has moved for enough away
            // from the initial MouseDown point.
            Point currentPoint = e.CurrentPosition;

            if (Math.Abs(currentPoint.X - dragStartPoint.X) > SystemParameters.MinimumHorizontalDragDistance ||
                Math.Abs(currentPoint.Y - dragStartPoint.Y) > SystemParameters.MinimumVerticalDragDistance)
            {
                this.isMouseDown = false;

                // Since we have to have the data before the drag starts, we don't allow a drag for data that
                // is not cached to avoid blocking the UI while the data is fetched before the drag starts.
                if (IsDataAvailable())
                {
                    IsInDrag = true;

                    int width  = (int)this.RenderSize.Width;
                    int height = (int)this.RenderSize.Height;

                    RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96.0, 96.0, PixelFormats.Pbgra32); // TODO: use actual dpi.
                    rtb.Render(this);

                    ConstrainSize(ref width, ref height, 200);
                    BitmapSource ghostImage = ResizeImage(rtb, width, height);

                    this.CaptureMouse();
                    Point mousePoint = new Point(0.5 * width, 0.5 * height);

#if USE_STANDARD_DRAGDROP
                    var dataObject = new System.Windows.DataObject();
                    var items      = GetData();
                    foreach (var item in items)
                    {
                        dataObject.SetData(item.Key, item.Value);
                    }

                    DragDrop.DoDragDrop(this, dataObject, DragDropEffects.Copy);
#else
                    try
                    {
                        DragSourceHelper.DoDragDrop(this, ghostImage, mousePoint, DragDropEffects.Copy, GetData());
                    }
                    catch (COMException)
                    {
                        // DragDropLib is buggy. Fail silently if this happens.
                    }
#endif

                    this.ReleaseMouseCapture();

                    IsInDrag = false;
                }
            }
        }
Пример #2
0
 private void HandleDragCompleted(object sender, DragContainerEventArgs e)
 {
     this.isMouseDown = false;
 }
Пример #3
0
 private void HandleDragStarted(object sender, DragContainerEventArgs e)
 {
     this.dragStartPoint = e.InitialPosition;
     this.isMouseDown    = true;
 }