internal override void OnMouseMove(MouseEventArgs e)
        {
            if (!IsLeftButtonDown || CheckOverScrollBar(e.GetPosition(TreeView)))
            {
                CleanUpAdorners();

                return;
            }

            if (!CanDrag)
            {
                return;
            }

            DragContent dragData = new DragContent();

            foreach (var item in draggableItems)
            {
                dragData.Add(item.Drag());
            }

            DragStart(dragData);
            DragDo(dragData);
            DragEnd();
            e.Handled = true;
        }
 private void DragStart(DragContent dragData)
 {
     initialCursor          = TreeView.Cursor;
     autoScroller.IsEnabled = true;
     if (dragAdorner == null)
     {
         dragAdorner = new DragAdorner(TreeView, dragData);
     }
 }
Beispiel #3
0
        // Be sure to call the base class constructor.
        public DragAdorner(TreeViewEx treeViewEx, DragContent content)
            : base(treeViewEx)
        {
            layer = AdornerLayer.GetAdornerLayer(treeViewEx);
            layer.Add(this);

            contentPresenter = new ContentPresenter();
            contentPresenter.Content = content;

            Binding b = new Binding("DragTemplate");
            b.Source = treeViewEx;
            b.Mode = BindingMode.OneWay;
            contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, b);
        }
Beispiel #4
0
        // Be sure to call the base class constructor.
        public DragAdorner(TreeViewEx treeViewEx, DragContent content)
            : base(treeViewEx)
        {
            layer = AdornerLayer.GetAdornerLayer(treeViewEx);
            layer.Add(this);

            contentPresenter         = new ContentPresenter();
            contentPresenter.Content = content;

            Binding b = new Binding("DragTemplate");

            b.Source = treeViewEx;
            b.Mode   = BindingMode.OneWay;
            contentPresenter.SetBinding(ContentPresenter.ContentTemplateProperty, b);
        }
        internal override void OnMouseMove(MouseEventArgs e)
        {
            IsDragging = false;

            if (!IsLeftButtonDown || CheckOverScrollBar(e.GetPosition(TreeView)))
            {
                CleanUpAdorners();
                return;
            }

            if (!CanDrag)
            {
                return;
            }

            //drag actually starting?
            Point  mousePos = e.GetPosition(null);
            Vector diff     = dragStartPoint - mousePos;

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

                DragContent dragData = new DragContent();
                foreach (var item in draggableItems)
                {
                    DragParameters dragParameters = new DragParameters(item);
                    TreeView.DragCommand.Execute(dragParameters);
                    dragData.Add(dragParameters.DraggedObject);
                }

                DragStart(dragData);
                DragDo(dragData);
                DragEnd();
                e.Handled = true;
            }
        }
        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;
                }
            }
        }
 private void DragDo(DragContent dragData)
 {
     DragDrop.DoDragDrop(TreeView, new DataObject(dragData), DragDropEffects.All);
 }
 private void DragStart(DragContent dragData)
 {
     autoScroller.IsEnabled = true;
 }
        internal override void OnMouseMove(MouseEventArgs e)
        {
            if (!IsLeftButtonDown ||CheckOverScrollBar(e.GetPosition(TreeView)))
            {
                CleanUpAdorners();

                return;
            }

            if (!CanDrag) return;

            DragContent dragData = new DragContent();
            foreach (var item in draggableItems)
            {
                dragData.Add(item.Drag());
            }

            DragStart(dragData);
            DragDo(dragData);
            DragEnd();
            e.Handled = true;
        }
        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;
                }
            }
        }
 private void DragStart(DragContent dragData)
 {
     initialCursor = TreeView.Cursor;
     autoScroller.IsEnabled = true;
     if (dragAdorner == null)
     {
         dragAdorner = new DragAdorner(TreeView, dragData);
     }
 }
 private void DragDo(DragContent dragData)
 {
     DragDrop.DoDragDrop(TreeView, new DataObject(dragData), DragDropEffects.All);
 }