Ejemplo n.º 1
0
        /// <summary> Element dropped. </summary>
        /// <param name="element"> Documentation in progress... </param>
        private void DoneDragDrop(UIElement element)
        {
            unwireTextBlockEvents();

            // backup drop index now since the call to UpdateTargetRegion below will modify the index
            int?backupDropIdx = dropIdx;

            // list index of dragged element
            int dragIdx = IndexOf(element);

            // reset default layout
            UpdateDropIndexAndAnimate(dragIdx, null, null);

            // remove preview adorner
            if (UsePreviewAdorner)
            {
                PreviewAdorner.detach(ref adorner);
            }

            // remove previously inserted border elements
            removeRowDefinitions();

            // reset mouse cursor
            Mouse.SetCursor(Cursors.Arrow);

            // no reordering necessary - at least fade dragged element in again
            if (FadeDraggedRow)
            {
                gridRows[dragIdx].animateOpacity(1, DraggedRowFadeInDuration, DraggedRowFadeInEasing);
            }

            // reorder elements if necessary
            if (reorderElements(backupDropIdx, dragIdx, false))
            {
                // fire events
                // Adapting the dropIdx according the convention of ObservableCollection.Move():
                // If dropIdx > dragIdx, the position number AFTER the insertion has to be used.
                RaiseRowMoved(dragIdx, backupDropIdx.Value > dragIdx ? backupDropIdx.Value - 1 : backupDropIdx.Value);
            }

            wireTextBlockEvents();
        }
Ejemplo n.º 2
0
        /// <summary> Move dragged element. </summary>
        /// <param name="element"> Documentation in progress... </param>
        private void DragMove(UIElement element)
        {
            // index of dragged item
            int dragIdx = IndexOf(element);

            // check if element position is over the grid
            bool movesInGrid = grid.Contains(Mouse.GetPosition(grid));

            // create / update preview adorner
            if (UsePreviewAdorner)
            {
                PreviewAdorner.attach(ref adorner, () => element as FrameworkElement, () => gridRows[dragIdx].Snapshot, 0.5);
                adorner.Offset = Vector.Add(Point.Subtract(Mouse.GetPosition(element), dragDropOrigin.Value), gridRows[dragIdx].GetSnapshotOffsetForAdorner(element));
            }

            Point?p = movesInGrid ? Mouse.GetPosition(grid) : (Point?)null;

            // update target index, animate rows
            UpdateDropIndexAndAnimate(dragIdx, p, new[] { dragIdx, dragIdx + 1 });

            // set cursor
            Mouse.SetCursor(movesInGrid && reorderElements(FindDropRegion(p), dragIdx, true) ? Cursors.Arrow : Cursors.No);
        }