Пример #1
0
 internal void TriggerInternalDragSourceDropped(DragSource source)
 {
     // Fire the drop target entered event
     if (InternalDragSourceDropped != null)
     {
         this.InternalDragSourceDropped(this, new DropEventArgs(source));
     }
 }
Пример #2
0
 internal void TriggerDropTargetLeft(DragSource source)
 {
     // Fire the drop target left event
     if (DropTargetLeft != null)
     {
         this.DropTargetLeft(this, new DropEventArgs(source));
     }
 }
Пример #3
0
        internal void TriggerDragSourceDropped(DragSource source)
        {
            // double-check: remove all borders

            source.RemoveAllDropBorders();

            // Fire the drop target dropped event
            if (DragSourceDropped != null)
            {
                this.DragSourceDropped(this, new DropEventArgs(source));
            }
        }
Пример #4
0
        /// <summary>
        /// Method overrides OnApplyTemplate to add handlers / get references to control in the template
        /// </summary>
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // all our controls are inside of a canvas control.  Because of this, it doesn't
            // automatically resize.  We need to make sure the parent control is resized properly

            // get the main control host
            MainControlHost = (Grid)this.GetTemplateChild("MainControlHost");
            // get the ghost control host
            GhostContentControl = (Grid)this.GetTemplateChild("GhostContentControl");
            // get the main content host
            MainContentControl = (Grid)this.GetTemplateChild("MainContentControl");

            // add the content
            if (plstContent.Children.Count > 0)
            {
                DragSource tmp = (DragSource)plstContent.Children[0];
                plstContent.Children.Remove(tmp);

                Content = tmp;
                //ResetContent();
            }

            // add the ghost?
            if (GhostVisibility == Visibility.Visible)
            {
                if (Ghost != null)
                {
                    GhostContentControl.Children.Clear();
                    GhostContentControl.Children.Add(Ghost);
                }
            }

            // get bounding border for hover-effects
            BoundingBorder = (Border)this.GetTemplateChild("BoundingBorder");

            // add handler for droptargetentered
            DropTargetEntered += new DropEventHandler(DropTargetBase_DropTargetEntered);

            // add handler for droptargetleft
            DropTargetLeft += new DropEventHandler(DropTargetBase_DropTargetLeft);

            // add handler for dragsourcedropped
            //DragSourceDropped += new DropEventHandler(DropTargetBase_DragSourceDropped);

            InternalDragSourceDropped += new DropEventHandler(DropTargetBase_InternalDragSourceDropped);

            if (AllowPositionSave)
            {
                (Application.Current.RootVisual as FrameworkElement).SizeChanged += new SizeChangedEventHandler(DropTarget_SizeChanged);
            }
        }
Пример #5
0
        /// <summary>
        /// Handles the dropping of a dragsource in this droptarget
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        void DropTargetBase_InternalDragSourceDropped(object sender, DropEventArgs args)
        {
            if (ShowHover)
            {
                // after this, start the hover-out animation on the droptarget
                Animation.CreateDropTargetHoverOut(BoundingBorder).Begin();
            }

            // what if there are children?
            if (MainContentControl.Children.Count > 0)
            {
                // get the current child (which is a dragsource by definition)
                // and either switch it with the new child (if the parent of the new child
                // is a valid droptarget for the current child - so it must have rights to
                // be used as a droptarget to be able to make the switch!) or replace it

                DragSource currentChild = (DragSource)MainContentControl.Children[0];

                // if currentchild <> child you're dragging (else, we're just dropping our
                // dragsource onto its own parent (droptarget)
                if (currentChild != args.DragSource)
                {
                    // is the new childs' parent (parent of parent of parent) a droptarget?
                    Panel firstParent = (Panel)VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(args.DragSource));

                    if (firstParent != null)
                    {
                        // droptarget?
                        if (VisualTreeHelper.GetParent(firstParent) is DropTarget)
                        {
                            DropTarget newChildParentDropTarget = (DropTarget)VisualTreeHelper.GetParent(firstParent);
                            if (currentChild.DropTargets.Contains(newChildParentDropTarget) ||
                                currentChild.AllDropTargetsValid == true)    // check for valid droptarget, or check if all droptargets are valid
                            {
                                // point needed for animation of the current child
                                Point from = new Point();
                                from = args.DragSource.getCurrentPosition();

                                Point offsetCurrentChild = new Point();
                                if (currentChild.ShowSwitchReplaceAnimation)
                                {
                                    offsetCurrentChild = currentChild.MainDraggableControl.TransformToVisual(InitialValues.ContainingLayoutPanel).Transform(new Point(0, 0));
                                }

                                Point oriOffset = new Point(args.DragSource.OriginalOffset.X, args.DragSource.OriginalOffset.Y);


                                // reset position of dragsource, so control is on top of ghost, right
                                // before actually moving it.
                                args.DragSource.ResetMyPosition();

                                // remove from current parent
                                ((Panel)VisualTreeHelper.GetParent(args.DragSource)).Children.Remove(args.DragSource);

                                MainContentControl.Children.Clear();
                                MainContentControl.Children.Add(args.DragSource);



                                // move the current child, with or without an animation
                                if (currentChild.ShowSwitchReplaceAnimation)
                                {
                                    // animation, from the current position to the new position
                                    // current position = where the new child is now
                                    // new position = where the new child was

                                    // add the current child to its new position, then move it from the
                                    // "current position" to 0, 0 (the new position)
                                    newChildParentDropTarget.MainContentControl.Children.Add(currentChild);

                                    //currentChild.AnimateOnSwitch(from);

                                    Storyboard sb = currentChild.ReturnAnimateOnSwitch(offsetCurrentChild, oriOffset);

                                    EventHandler handler = null;
                                    handler = (send, arg) =>
                                    {
                                        sb.Completed -= handler;
                                        currentChild.ResetMyPosition();
                                        // trigger external dragsourcedropped-event
                                        TriggerDragSourceDropped(args.DragSource);
                                    };
                                    sb.Completed += handler;
                                    sb.Begin();
                                }
                                else
                                {
                                    // no animation
                                    newChildParentDropTarget.MainContentControl.Children.Add(currentChild);

                                    // trigger external dragsourcedropped-event
                                    TriggerDragSourceDropped(args.DragSource);
                                }
                            }
                            else
                            {
                                // parent of the new child isn't a VALID droptarget.  Depending on DropBehaviour, remove
                                // current child & set new one (replace-behaviour) or return the new child to
                                // its original position (disallow-behaviour)

                                if (RemoveElementDropBehaviour == RemoveElementDropBehaviour.Replace)
                                {
                                    // reset position of dragsource, so control is on top of ghost, right
                                    // before actually moving it.
                                    args.DragSource.ResetMyPosition();

                                    // remove from current parent
                                    ((Panel)VisualTreeHelper.GetParent(args.DragSource)).Children.Remove(args.DragSource);

                                    MainContentControl.Children.Clear();
                                    MainContentControl.Children.Add(args.DragSource);

                                    // trigger external dragsourcedropped-event
                                    TriggerDragSourceDropped(args.DragSource);
                                }
                                else
                                {
                                    // drop is disallowed, return dragsource to original position

                                    args.DragSource.ReturnToOriginalPosition();

                                    // trigger external dragsourcedropped-event
                                    TriggerDragSourceDropped(args.DragSource);
                                }
                            }
                        }
                        else
                        {
                            // parent of the new child isn't a droptarget.  Depending on DropBehaviour, remove
                            // current child & set new one (replace-behaviour) or return the new child to
                            // its original position (disallow-behaviour)

                            if (RemoveElementDropBehaviour == RemoveElementDropBehaviour.Replace)
                            {
                                // reset position of dragsource, so control is on top of ghost, right
                                // before actually moving it.
                                args.DragSource.ResetMyPosition();

                                // remove from current parent
                                ((Panel)VisualTreeHelper.GetParent(args.DragSource)).Children.Remove(args.DragSource);

                                MainContentControl.Children.Clear();
                                MainContentControl.Children.Add(args.DragSource);

                                // trigger external dragsourcedropped-event
                                TriggerDragSourceDropped(args.DragSource);
                            }
                            else
                            {
                                // drop is disallowed, return dragsource to original position

                                args.DragSource.ReturnToOriginalPosition();

                                // trigger external dragsourcedropped-event
                                TriggerDragSourceDropped(args.DragSource);
                            }
                        }
                    }
                    else
                    {
                        // reset position of dragsource, so control is on top of ghost, right
                        // before actually moving it.
                        args.DragSource.ResetMyPosition();

                        // remove from current parent
                        ((Panel)VisualTreeHelper.GetParent(args.DragSource)).Children.Remove(args.DragSource);

                        MainContentControl.Children.Clear();
                        MainContentControl.Children.Add(args.DragSource);

                        // trigger external dragsourcedropped-event
                        TriggerDragSourceDropped(args.DragSource);
                    }
                }
                else
                {
                    // reset position of dragsource, so control is on top of ghost, right
                    // before actually moving it.
                    args.DragSource.ResetMyPosition();

                    // trigger external dragsourcedropped-event
                    TriggerDragSourceDropped(args.DragSource);
                }
            }
            else
            {
                // reset position of dragsource, so control is on top of ghost, right
                // before actually moving it.
                args.DragSource.ResetMyPosition();

                // remove from current parent
                ((Panel)VisualTreeHelper.GetParent(args.DragSource)).Children.Remove(args.DragSource);

                MainContentControl.Children.Clear();
                MainContentControl.Children.Add(args.DragSource);

                ((DropTarget)VisualTreeHelper.GetParent((Panel)VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(args.DragSource)))).Content = null;
                this.Content = args.DragSource;

                // trigger external dragsourcedropped-event
                TriggerDragSourceDropped(args.DragSource);
            }
        }
Пример #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="source"></param>
 public DropEventArgs(DragSource source)
 {
     DragSource = source;
 }