Exemplo n.º 1
0
        private void Source_MouseMove(object s, MouseEventArgs e)
        {
            if (IsInitialized())
            {
                if (!IsDragging)
                {
                    if (IsMouseDetecting)
                    {
                        // Get the current mouse position
                        Point  mousePos = e.GetPosition(null);
                        Vector diff     = StartPoint - mousePos;

                        if (e.LeftButton == MouseButtonState.Pressed &&
                            Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                            Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
                        {
                            DragStartEventArgs ea = new DragStartEventArgs();

                            // Invoke the DragStart event on the source to allow it to set the package contents.
                            DragStart.GetInvocationList().Where(d => d.Target == s).First().DynamicInvoke(ea);

                            DataObject dragData = new DataObject(Name, ea.Package);

                            IsMouseDetecting = false;
                            IsDragging       = true;
                            currentSource    = s as UIElement;

                            // This blocks until the drop operation completes.
                            System.Windows.DragDrop.DoDragDrop((s as UIElement), dragData, DragDropEffects.Move | DragDropEffects.None);

                            IsDragging    = false;
                            currentSource = null;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void Source_MouseMove(object s, MouseEventArgs e)
        {
            if (IsInitialized())
            {
                if (!IsDragging)
                {
                    if (IsMouseDetecting)
                    {
                        // Get the current mouse position
                        Point mousePos = e.GetPosition(null);
                        Vector diff = StartPoint - mousePos;

                        if (e.LeftButton == MouseButtonState.Pressed &&
                            Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                            Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance)
                        {
                            DragStartEventArgs ea = new DragStartEventArgs();

                            // Invoke the DragStart event on the source to allow it to set the package contents.
                            DragStart.GetInvocationList().Where(d => d.Target == s).First().DynamicInvoke(ea);

                            DataObject dragData = new DataObject(Name, ea.Package);

                            IsMouseDetecting = false;
                            IsDragging = true;
                            currentSource = s as UIElement;

                            // This blocks until the drop operation completes.
                            System.Windows.DragDrop.DoDragDrop((s as UIElement), dragData, DragDropEffects.Move | DragDropEffects.None);

                            IsDragging = false;
                            currentSource = null;
                        }
                    }
                }
            }
        }