Пример #1
0
 /// <summary>
 /// Used to handle the DragDrop event.
 /// Determines the target and fires the corresponding action (move or copy).
 /// </summary>
 /// <param name="source">The source of the event</param>
 /// <param name="e">The event arguments</param>
 public void HandleDragDrop(object source, DragDropEventArgs e)
 {
     if (e.Effect != DragDropEffect.None)
     {
         // make the move...
         C1TreeViewItem item = e.DragSource as C1TreeViewItem;
         if (item != null)
         {
             // find target node
             C1TreeViewItem target = Tree.GetNode(e.GetPosition(null));
             if (target != null)
             {
                 Point p = e.GetPosition(target);
                 bool insertAfter = (p.Y > target.RenderSize.Height / 2);
                 if (Effect == DragDropEffect.Move)
                 {
                     DoMove(item, target, insertAfter);
                 }
                 else
                 {
                     DoCopy(item, target, insertAfter);
                 }
             }
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Handles the DragDrop event.
        /// Determines the target and fires the corresponding action (move or copy).
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        private void HandleDragDrop(object source, DragDropEventArgs e)
        {
            if (e.Effect != DragDropEffect.None)
            {
                // make the move...
                C1TreeViewItem item = e.DragSource as C1TreeViewItem;
                if (item != null)
                {
                    // find target node
                    C1TreeViewItem target = Tree.GetNode(e.GetPosition(null));
                    if (target != null)
                    {
                        bool insertAfter = e.GetPosition(target).Y > 4;
                        if (target.HasItems)
                        {
                            // if target is department, insert new item inside
                            target      = target.FirstNode;
                            insertAfter = false;
                        }
                        if (Effect == DragDropEffect.Move)
                        {
                            DoMove(item, target, insertAfter);
                        }
                        else
                        {
                            DoCopy(item, target, insertAfter);
                        }

                        Tree.ItemsSource = Tree.ItemsSource;
                    }
                }
            }
        }
        // get a valid drop range
        CellRange GetDropRange(DragDropEventArgs e)
        {
            // get source, target
            var src = GetParentOfType <C1FlexGrid>(e.DragSource);
            var dst = GetDropTarget(e);

            // get target range from mouse position
            var pt = e.GetPosition(dst);

            pt.X -= _dragOffset.X;
            pt.Y -= _dragOffset.Y;
            var ht  = dst.HitTest(pt);
            var rng = ht.CellRange;

            if (rng.Row < 0)
            {
                rng.Row = 0;
            }
            if (rng.Column < 0)
            {
                rng.Column = 0;
            }

            // expand to match size of source range
            var sel = src.Selection;

            rng.Row2    = Math.Min(rng.Row + sel.RowSpan - 1, dst.Rows.Count - 1);
            rng.Column2 = Math.Min(rng.Column + sel.ColumnSpan - 1, dst.Columns.Count - 1);

            // done
            return(rng);
        }
Пример #4
0
 // get drop location within a ListBox
 public static int GetDropIndex(DragDropEventArgs e, ListBox target)
 {
     int index = 0;
     foreach (UIElement child in target.Items)
     {
         Point p = e.GetPosition(child);
         if (p.Y - child.DesiredSize.Height / 2 < 0) break;
         index++;
     }
     return index;
 }
        // get drop location within a ListBox
        public static int GetDropIndex(DragDropEventArgs e, ListBox target)
        {
            int index = 0;

            foreach (UIElement child in target.Items)
            {
                Point p = e.GetPosition(child);
                if (p.Y - child.DesiredSize.Height / 2 < 0)
                {
                    break;
                }
                index++;
            }
            return(index);
        }
        // handle user dragging a cell to a new position
        void _ddMgr_DragDrop(object source, DragDropEventArgs e)
        {
            if (_dragViewObject != null)
            {
                // get target cell
                var ht = _flex.HitTest(e.GetPosition(_flex));
                if (ht.CellType == CellType.Cell && ht.Row > -1 && ht.Column > -1)
                {
                    // move object to target cell
                    var oldRange = new CellRange(e.DragSource);
                    _flex[oldRange.Row, oldRange.Column] = null;
                    _flex[ht.Row, ht.Column]             = _dragViewObject.DataObject;

                    // and move the selection
                    _flex.Select(ht.Row, ht.Column);
                    _dragViewObject = null;
                }
            }
        }
Пример #7
0
        // handle user dragging a cell to a new position
        void _ddMgr_DragDrop(object source, DragDropEventArgs e)
        {
            // get view object being dragged
            var bdr = e.DragSource as Border;
            var viewObject = bdr.Child as MyViewObject;
            if (viewObject != null)
            {
                // get target cell
                var ht = _flex.HitTest(e.GetPosition(_flex));
                if (ht.CellType == CellType.Cell && ht.Row > -1 && ht.Column > -1)
                {
                    // move object to target cell
                    var oldRange = new CellRange(bdr);
                    _flex[oldRange.Row, oldRange.Column] = null;
                    _flex[ht.Row, ht.Column] = viewObject.DataObject;

                    // and move the selection
                    _flex.Select(ht.Row, ht.Column);
                }
            }
        }
Пример #8
0
        /// <summary>
        /// Used to handle the DragOver event.
        /// Adds the mark to indicate the drop target
        /// Determines if a given node of the tree is a valid drop location
        /// </summary>
        /// <param name="source">The source of the event</param>
        /// <param name="e">The event arguments</param>
        public void HandleDragOver(object source, DragDropEventArgs e)
        {
            C1DragDropManager dragDropManager = source as C1DragDropManager;
            if (Mark.Parent == null)
                dragDropManager.Canvas.Children.Add(Mark);
            Mark.Visibility = Visibility.Collapsed;
            e.Effect = DragDropEffect.None;

            // Check if is a valid drop action
            C1TreeViewItem target = Tree.GetNode(e.GetPosition(null));
            if (IsValidDrop(e.DragSource as C1TreeViewItem, target))
            {
                // get target with respect to drag/drop canvas
                Point p = target.C1TransformToVisual(dragDropManager.Canvas).Transform(new Point());
                Point pos = e.GetPosition(target);
                if (pos.Y > target.RenderSize.Height / 2)
                {
                    p.Y += target.RenderSize.Height;
                }
                Mark.SetValue(Canvas.LeftProperty, p.X);
                Mark.SetValue(Canvas.TopProperty, p.Y);
                Mark.Visibility = Visibility.Visible;
                e.Effect = DragDropEffect.Move;
            }
        }