private void OnDrop(object sender, DragEventArgs e)
        {
            TreeViewExItem item = GetTreeViewItemUnderMouse(e.GetPosition(TreeView));

            if (item == null)
            {
                CleanUpAdorners();
                return;
            }

            CanInsertReturn canInsertReturn = CanInsert(item, e.GetPosition, e.Data);

            if (canInsertReturn != null)
            {
                // insert and return

                item.ParentTreeViewItem.Insert(canInsertReturn.Index, e.Data.GetData(canInsertReturn.Format));
                CleanUpAdorners();
                return;
            }

            // check if drop is possible
            string dropformat = CanDrop(item, e.Data);

            if (dropformat != null)
            {
                // drop and return
                object data = e.Data.GetData(dropformat);
                item.DropAction(data);
            }

            CleanUpAdorners();
        }
Esempio n. 2
0
        private void OnDrop(object sender, DragEventArgs e)
        {
            TreeViewExItem item = GetTreeViewItemUnderMouse(e.GetPosition(TreeView));
            //if (item == null)
            //{
            //    CleanUpAdorners();
            //    return;
            //}

            CanInsertReturn canInsertReturn = CanInsert(item, e.GetPosition, e.Data);

            if (canInsertReturn != null)
            {
                // insert and return
                TreeView.DropCommand.Execute(new DropParameters(item.ParentTreeViewItem, e.Data, canInsertReturn.Index));
                CleanUpAdorners();
                return;
            }

            // check if drop is possible
            if (CanDrop(item, e.Data))
            {
                // drop and return
                TreeView.DropCommand.Execute(new DropParameters(item, e.Data));
            }

            CleanUpAdorners();
        }
        void OnDragOver(object sender, DragEventArgs e)
        {
            // drag over is the only event which returns the position
            // GiveFeedback returns nonsense even from Mouse.GetPosition
            Point point = e.GetPosition(TreeView);

            if (TryScroll(point))
            {
                return;
            }

            if (dragAdorner == null)//external drop
            {
                var content = new DragContent();
                content.Add(e.Data);
                dragAdorner = new DragAdorner(TreeView, content);
            }

            dragAdorner.UpdatePosition(point);
            if (IsMouseOverAdorner(point))
            {
                return;
            }
            var itemsPresenter = TreeView.ScrollViewer.Content as ItemsPresenter;

            if (itemsPresenter.InputHitTest(e.GetPosition(itemsPresenter)) == null)
            {
                dragAdorner.Content.CanDrop   = false;
                dragAdorner.Content.CanInsert = false;
                //dragAdorner.Content.InsertIndex = -1;
                if (insertAdorner != null)
                {
                    insertAdorner.Dispose();
                }
                return;
            }

            if (itemMouseIsOver != null)
            {
                itemMouseIsOver.IsCurrentDropTarget = false;
            }

            itemMouseIsOver = GetTreeViewItemUnderMouse(point);
            if (itemMouseIsOver == null)
            {
                return;
            }
            CanInsertReturn canInsertReturn = CanInsert(itemMouseIsOver, e.GetPosition, e.Data);

            if (canInsertReturn != null)
            {
                dragAdorner.Content.CanDrop   = false;
                dragAdorner.Content.CanInsert = true;
                //dragAdorner.Content.InsertIndex = canInsertReturn.Index;

                if (insertAdorner == null)
                {
                    insertAdorner = new InsertAdorner(itemMouseIsOver, new InsertContent {
                        Before = canInsertReturn.Before
                    });
                }
                else
                {
                    insertAdorner.Dispose();
                    insertAdorner = new InsertAdorner(itemMouseIsOver, new InsertContent {
                        Before = canInsertReturn.Before
                    });
                }

                itemMouseIsOver.IsCurrentDropTarget = false;
            }
            else
            {
                dragAdorner.Content.CanInsert = false;
                //dragAdorner.Content.InsertIndex = -1;
                if (insertAdorner != null)
                {
                    insertAdorner.Dispose();
                    insertAdorner = null;
                }

                dragAdorner.Content.CanDrop = CanDrop(itemMouseIsOver, e.Data) != null;
                if (itemMouseIsOver != null)
                {
                    itemMouseIsOver.IsCurrentDropTarget = true;
                }
            }
        }
Esempio n. 4
0
        void OnDragOver(object sender, DragEventArgs e)
        {
            e.Effects = DragDropEffects.None;
            e.Handled = true;

            // drag over is the only event which returns the position
            Point point = e.GetPosition(TreeView);

            if (TryScroll(point))
            {
                return;
            }

            if (IsMouseOverAdorner(point))
            {
                return;
            }
            var itemsPresenter = TreeView.ScrollViewer.Content as ItemsPresenter;

            /*
             * if (itemsPresenter.InputHitTest(e.GetPosition(itemsPresenter)) == null)
             * {
             *  if (insertAdorner != null) insertAdorner.Dispose();
             *  return;
             * }
             */

            if (itemMouseIsOver != null)
            {
                itemMouseIsOver.IsCurrentDropTarget = false;
            }

            itemMouseIsOver = GetTreeViewItemUnderMouse(point);
            //if (itemMouseIsOver == null) return;
            CanInsertReturn canInsertReturn = CanInsert(itemMouseIsOver, e.GetPosition, e.Data);

            if (canInsertReturn != null)
            {
                e.Effects = DragDropEffects.Move;

                if (insertAdorner == null)
                {
                    insertAdorner = new InsertAdorner(itemMouseIsOver, new InsertContent {
                        Before = canInsertReturn.Before
                    });
                }
                else
                {
                    insertAdorner.Dispose();
                    insertAdorner = new InsertAdorner(itemMouseIsOver, new InsertContent {
                        Before = canInsertReturn.Before
                    });
                }

                itemMouseIsOver.IsCurrentDropTarget = false;
            }
            else
            {
                if (insertAdorner != null)
                {
                    insertAdorner.Dispose();
                    insertAdorner = null;
                }

                if (CanDrop(itemMouseIsOver, e.Data))
                {
                    e.Effects = DragDropEffects.Move;
                }
                if (itemMouseIsOver != null)
                {
                    itemMouseIsOver.IsCurrentDropTarget = true;
                }
            }
        }