Exemplo n.º 1
0
        static bool UpdateEffects(object uiObject, DragEventArgs e)
        {
            try
            {
                DropTargetBase advisor = GetDropTarget(uiObject as DependencyObject);
                if (advisor.IsValidDataObject(e.Data) == false)
                {
                    return(false);
                }

                if ((e.AllowedEffects & DragDropEffects.Move) == 0 &&
                    (e.AllowedEffects & DragDropEffects.Copy) == 0)
                {
                    e.Effects = DragDropEffects.None;
                    return(true);
                }

                if ((e.AllowedEffects & DragDropEffects.Move) != 0 &&
                    (e.AllowedEffects & DragDropEffects.Copy) != 0)
                {
                    if ((e.KeyStates & DragDropKeyStates.ControlKey) != 0)
                    {
                    }
                    e.Effects = ((e.KeyStates & DragDropKeyStates.ControlKey) != 0) ?
                                DragDropEffects.Copy : DragDropEffects.Move;
                }

                return(true);
            }
            catch (Exception ex)
            {
                VMuktiHelper.ExceptionHandler(ex, "UpdateEffects()", "Controls\\VMuktiGrid\\DragDropManager\\DragDropManager.cs");
                return(false);
            }
        }
Exemplo n.º 2
0
        /* ____________________________________________________________________
         *		Drop Target events
         * ____________________________________________________________________
         */
        static void DropTarget_PreviewDrop(object sender, DragEventArgs e)
        {
            try
            {
                if (UpdateEffects(sender, e) == false)
                {
                    return;
                }

                DropTargetBase advisor   = GetDropTarget(sender as DependencyObject);
                Point          dropPoint = e.GetPosition(sender as UIElement);

                // Calculate displacement for (Left, Top)
                Point offset = e.GetPosition(_overlayElt);
                dropPoint.X = dropPoint.X - offset.X;
                dropPoint.Y = dropPoint.Y - offset.Y;

                advisor.OnDropCompleted(e.Data, dropPoint);
                RemovePreviewAdorner();
                _offsetPoint = new Point(0, 0);
            }
            catch (Exception ex)
            {
                VMuktiHelper.ExceptionHandler(ex, "DropTarget_PreviewDrop()", "Controls\\VMuktiGrid\\DragDropManager\\DragDropManager.cs");
            }
        }
Exemplo n.º 3
0
        static void DropTarget_PreviewDragLeave(object sender, DragEventArgs e)
        {
            try
            {
                if (UpdateEffects(sender, e) == false)
                {
                    return;
                }

                DropTargetBase advisor    = GetDropTarget(sender as DependencyObject);
                Point          mousePoint = MouseUtilities.GetMousePosition(advisor.TargetUI);

                //Console.WriteLine("Inside DropTarget_PreviewDragLeave1" + mousePoint.X.ToString() + "|" + mousePoint.Y.ToString());
                //giving a tolerance of 2 so that the adorner is removed when the mouse is moved fast.
                //this might still be small...in that case increase the tolerance
                if ((mousePoint.X < 2) || (mousePoint.Y < 2) ||
                    (mousePoint.X > ((FrameworkElement)(advisor.TargetUI)).ActualWidth - 2) ||
                    (mousePoint.Y > ((FrameworkElement)(advisor.TargetUI)).ActualHeight - 2))
                {
                    RemovePreviewAdorner();
                }
                e.Handled = true;
            }
            catch (Exception ex)
            {
                VMuktiHelper.ExceptionHandler(ex, "DropTarget_PreviewDragLeave()", "Controls\\VMuktiGrid\\DragDropManager\\DragDropManager.cs");
            }
        }
Exemplo n.º 4
0
        private static void OnDropTargetChanged(DependencyObject depObj, DependencyPropertyChangedEventArgs args)
        {
            try
            {
                UIElement targetElt = depObj as UIElement;
                if (args.NewValue != null && args.OldValue == null)
                {
                    targetElt.PreviewDragEnter += new DragEventHandler(DropTarget_PreviewDragEnter);
                    targetElt.PreviewDragOver  += new DragEventHandler(DropTarget_PreviewDragOver);
                    targetElt.PreviewDragLeave += new DragEventHandler(DropTarget_PreviewDragLeave);
                    targetElt.PreviewDrop      += new DragEventHandler(DropTarget_PreviewDrop);

                    targetElt.AllowDrop = true;

                    // Set the Drag source UI
                    DropTargetBase advisor = args.NewValue as DropTargetBase;
                    advisor.TargetUI = targetElt;
                }
                else if (args.NewValue == null && args.OldValue != null)
                {
                    targetElt.PreviewDragEnter -= DropTarget_PreviewDragEnter;
                    targetElt.PreviewDragOver  -= DropTarget_PreviewDragOver;
                    targetElt.PreviewDragLeave -= DropTarget_PreviewDragLeave;
                    targetElt.PreviewDrop      -= DropTarget_PreviewDrop;


                    targetElt.AllowDrop = false;
                }
            }

            catch (Exception ex)
            {
                VMuktiHelper.ExceptionHandler(ex, "OnDropTargetChanged()", "Controls\\VMuktiGrid\\DragDropManager\\DragDropManager.cs");
            }
        }
Exemplo n.º 5
0
        static void DropTarget_PreviewDragEnter(object sender, DragEventArgs e)
        {
            try
            {
                if (UpdateEffects(sender, e) == false)
                {
                    return;
                }

                // Setup the preview Adorner
                UIElement feedbackUI = GetDropTarget(sender as DependencyObject).GetVisualFeedback(e.Data);
                _offsetPoint = GetOffsetPoint(e.Data);

                DropTargetBase advisor = GetDropTarget(sender as DependencyObject);

                Point mousePoint = MouseUtilities.GetMousePosition(advisor.TargetUI);

                // Console.WriteLine("Inside DropTarget_PreviewDragEnter" + mousePoint.X.ToString() + "|" + mousePoint.Y.ToString());

                //giving a tolerance of 2 so that the adorner is created when the mouse is moved fast.
                //this might still be small...in that case increase the tolerance
                if ((mousePoint.X < 2) || (mousePoint.Y < 2) ||
                    (mousePoint.X > ((FrameworkElement)(advisor.TargetUI)).ActualWidth - 2) ||
                    (mousePoint.Y > ((FrameworkElement)(advisor.TargetUI)).ActualHeight - 2) ||
                    (_overlayElt == null))
                {
                    CreatePreviewAdorner(sender as UIElement, feedbackUI);
                }

                e.Handled = true;
            }
            catch (Exception ex)
            {
                VMuktiHelper.ExceptionHandler(ex, "DropTarget_PreviewDragEnter()", "Controls\\VMuktiGrid\\DragDropManager\\DragDropManager.cs");
            }
        }