示例#1
0
        /// <summary>
        /// Drop event to call the respective classes to handle
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            if (dataType != null)
            {
                //if the data type can be dropped
                if (e.Data.GetDataPresent(dataType))
                {
                    //drop the data
                    IDropable target = AssociatedObject.DataContext as IDropable;
                    if (target.CanDrop)
                    {
                        target.Drop(e.Data.GetData(dataType));

                        //remove the data from the source
                        IDragable source = e.Data.GetData(dataType) as IDragable;
                        source.Remove(e.Data.GetData(dataType));
                    }
                }
            }
            if (adorner != null)
            {
                adorner.Remove();
            }

            e.Handled = true;
            return;
        }
示例#2
0
        void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            if (_dataType != null)
            {
                //if the data type can be dropped
                if (e.Data.GetDataPresent(_dataType))
                {
                    //drop the data
                    IDropable target = AssociatedObject.DataContext as IDropable;
                    //var point = e.GetPosition(this.AssociatedObject.DataContext as IInputElement);
                    if (target != null)
                    {
                        target.Drop(e.Data.GetData(_dataType), e);
                    }

                    //remove the data from the source
                    IDragable source = e.Data.GetData(_dataType) as IDragable;
                    if (source != null)
                    {
                        source.Remove(e.Data.GetData(_dataType));
                    }
                }
            }

            //if (this.adorner != null)
            //    this.adorner.Remove();

            e.Handled = true;
        }
        void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            if (dataType != null)
            {
                if (e.Data.GetDataPresent(dataType))
                {
                    IDropable target = this.AssociatedObject.DataContext as IDropable;
                    target.Drop(e);

                    IDragable source = e.Data.GetData(dataType) as IDragable;
                    source.Remove();
                }
            }
        }
        /// <summary>
        /// The associated object_ drop.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void AssociatedObject_Drop(object sender, DragEventArgs e)
        {
            // if the data type can be dropped
            if (this.dataType != null)
            {
                if (e.Data.GetDataPresent(this.dataType))
                {
                    // first find the UIElement that it was dropped over, then we determine if it's
                    // dropped above or under the UIElement, then insert at the correct index.
                    ItemsControl dropContainer = sender as ItemsControl;

                    // get the UIElement that was dropped over
                    UIElement droppedOverItem = UIHelper.GetUIElement(dropContainer, e.GetPosition(dropContainer));
                    int       dropIndex       = -1; // the location where the item will be dropped
                    dropIndex = dropContainer.ItemContainerGenerator.IndexFromContainer(droppedOverItem) + 1;

                    // find if it was dropped above or below the index item so that we can insert
                    // the item in the correct place
                    if (UIHelper.IsPositionAboveElement(droppedOverItem, e.GetPosition(droppedOverItem)))
                    {
                        // if above
                        dropIndex = dropIndex - 1; // we insert at the index above it
                    }

                    // remove the data from the source
                    IDragable source = e.Data.GetData(this.dataType) as IDragable;
                    source.Remove(e.Data.GetData(this.dataType));

                    // drop the data
                    IDropable target = this.AssociatedObject.DataContext as IDropable;
                    target.Drop(e.Data.GetData(this.dataType), dropIndex);
                }
            }

            if (this.insertAdornerManager != null)
            {
                this.insertAdornerManager.Clear();
            }

            e.Handled = true;
            return;
        }
示例#5
0
        private void AssociatedObject_MouseMove(object sender, MouseEventArgs e)
        {
            if (_isMouseClicked)
            {
                Point p = e.GetPosition(this.AssociatedObject);
                Debug.WriteLine("moving " + p.X + "," + p.Y);
                if (_isDragging)
                {
                    // update adorner
                    UpdateDragAdorner(p);
                }
                else
                {
                    if (Math.Abs(p.X - _original.X) > 10 || Math.Abs(p.Y - _original.Y) > 10)
                    {
                        _isDragging = true;

                        FrameworkElement el     = this.AssociatedObject;
                        FrameworkElement dragEl = null;
                        while ((FrameworkElement)VisualTreeHelper.GetParent(el) != null)
                        {
                            el = (FrameworkElement)VisualTreeHelper.GetParent(el);
                            if (AdornerLayer.GetAdornerLayer(el) != null)
                            {
                                _el = el;
                            }
                            if (el.DataContext is IDragable)
                            {
                                dragEl = el;
                            }
                        }

                        // get dragable parent
                        //while (!(el.DataContext is IDragable))
                        //    el = (FrameworkElement)VisualTreeHelper.GetParent(el);

                        IDragable dragObject = dragEl.DataContext as IDragable;
                        if (dragObject != null)
                        {
                            Mouse.Capture(null);

                            // init adorner
                            Point pp       = e.GetPosition(_el);
                            Point newpoint = new Point(pp.X - _original.X, pp.Y - _original.Y);
                            InitializeDragAdorner(this.AssociatedObject.DataContext, newpoint);

                            // start dragging
                            DataObject data = new DataObject();
                            data.SetData(dragObject.DragableDataType, this.AssociatedObject.DataContext);
                            //DragDropEffects effect = System.Windows.DragDrop.DoDragDrop(this.AssociatedObject, data, DragDropEffects.Move);
                            DragDropEffects effect = System.Windows.DragDrop.DoDragDrop(this.AssociatedObject,
                                                                                        new DragWrapper
                            {
                                Item     = data,
                                DragInfo = _itemAdorner
                            },
                                                                                        DragDropEffects.Move);

                            // done dragging
                            Mouse.Capture(null);
                            _isMouseClicked = false;
                            _isDragging     = false;
                            DestroyAdorner();
                            if (effect == DragDropEffects.Move)
                            {
                                dragObject.Remove(this.AssociatedObject.DataContext);
                            }
                        }
                    }
                }
            }
        }