예제 #1
0
        //Rearrangement
        private void dragObject_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            mouseLeftButtonDown = false;
            bool arranged = false;

            if (isDragging)
            {
                isDragging = false;

                foreach (DragObject c in dragList)
                {
                    System.Windows.Controls.Control con = sender as System.Windows.Controls.Control;
                    con.ReleaseMouseCapture();
                    if (draggingTarget.rearrange)
                    {
                        if (c.rearrange)
                        {
                            if (draggingTarget.draggingMode == DraggingMode.Horizontal)
                            {
                                //if (draggingTarget.target.Margin.Left > c.target.Margin.Left &&
                                //    draggingTarget.target.Margin.Left < c.target.Margin.Left + c.target.Width &&
                                //    draggingTarget.target.Margin.Top == c.target.Margin.Top)
                                if (Canvas.GetLeft(draggingTarget.target) > Canvas.GetLeft(c.target) &&
                                    Canvas.GetLeft(draggingTarget.target) < Canvas.GetLeft(c.target) + c.target.Width &&
                                    Canvas.GetTop(draggingTarget.target) == Canvas.GetTop(c.target))
                                {
                                    //draggingTarget.target.Margin = c.target.Margin;
                                    //c.target.Margin = originalTargetPos;
                                    SetPoint(draggingTarget.target, GetPoint(c.target));
                                    SetPoint(c.target, originalTargetPos);
                                    arranged = true;
                                    Console.WriteLine("Rearrange");
                                }
                            }
                            else if (draggingTarget.draggingMode == DraggingMode.Vertical)
                            {
                                if (Canvas.GetTop(draggingTarget.target) > Canvas.GetTop(c.target) &&
                                    Canvas.GetTop(draggingTarget.target) < Canvas.GetTop(c.target) + c.target.Height &&
                                    Canvas.GetLeft(draggingTarget.target) == Canvas.GetLeft(c.target))
                                {
                                    SetPoint(draggingTarget.target, GetPoint(c.target));
                                    SetPoint(c.target, originalTargetPos);
                                    arranged = true;
                                    Console.WriteLine("Rearrange");
                                }
                            }
                            else if (draggingTarget.draggingMode == DraggingMode.Both)
                            {
                                if (Canvas.GetLeft(draggingTarget.target) > Canvas.GetLeft(c.target) &&
                                    Canvas.GetLeft(draggingTarget.target) < Canvas.GetLeft(c.target) + c.target.Width &&
                                    Canvas.GetTop(draggingTarget.target) > Canvas.GetTop(c.target) &&
                                    Canvas.GetTop(draggingTarget.target) < Canvas.GetTop(c.target) + c.target.Height)
                                {
                                    SetPoint(draggingTarget.target, GetPoint(c.target));
                                    SetPoint(c.target, originalTargetPos);
                                    arranged = true;
                                    Console.WriteLine("Rearrange");
                                }
                            }
                        }
                    }
                }

                if (!arranged)
                {
                    SetPoint(draggingTarget.target, originalTargetPos);
                    Console.WriteLine("No Intersection");
                }
                Canvas.SetZIndex(draggingTarget.target, 0);
                Canvas.SetZIndex(dragCanvas, 0);
            }
        }