Example #1
0
        internal DragStartingContext InitializeReorder()
        {
            var dragVisual = this.ListView.DragBehavior.GetReorderVisual(this);

            if (dragVisual == null)
            {
                this.dragVisual = this.ListView.GetContainerForItem();

                this.dragVisual.Orientation   = this.Orientation;
                this.dragVisual.Width         = this.ActualWidth;
                this.dragVisual.Height        = this.ActualHeight;
                this.dragVisual.ListView      = this.ListView;
                this.dragVisual.isDragContent = true;
                this.dragVisual.IsSelected    = this.IsSelected;
                this.ListView.PrepareContainerForItem(this.dragVisual, this.DataContext);
            }

            (dragVisual as IDragDropElement).SkipHitTest = true;

            DragDrop.SetDragPositionMode(this, this.ListView.Orientation == Orientation.Vertical ? DragPositionMode.RailY : DragPositionMode.RailX);

            this.Opacity = 0.0;

            var surface = new CanvasDragSurface(this.ListView.childrenPanel as FrameworkElement, this.ListView.childrenPanel as Canvas, true);

            var payload = new ReorderItemsDragOperation(this, this.DataContext);

            this.ListView.DragBehavior.OnReorderStarted(this.DataContext);

            return(new DragStartingContext {
                DragVisual = dragVisual, Payload = payload, DragSurface = surface, HitTestStrategy = new ReorderListViewItemHitTestStrategy(this, surface.RootElement)
            });
        }
        private object GetDestinationDataItem(ReorderItemsDragOperation data)
        {
            IEnumerable enumerableSource = this.ListView.ItemsSource as IEnumerable;
            IEnumerator enumerator       = enumerableSource.GetEnumerator();
            int         i = 0;

            while (i++ <= data.CurrentSourceReorderIndex)
            {
                enumerator.MoveNext();
            }
            object destinationDataItem = enumerator.Current;

            return(destinationDataItem);
        }
Example #3
0
        private bool ShouldReorder(Point position, ReorderItemsDragOperation data)
        {
            if (this.reorderCoordinator == null)
            {
                return(false);
            }

            var sourceElement = this.reorderCoordinator.Host.ElementAt(data.CurrentSourceReorderIndex);

            var startPosition = this.ListView.Orientation == Orientation.Horizontal ? position.X : position.Y;
            var itemLength    = this.ListView.Orientation == Orientation.Horizontal ? this.ActualWidth : this.ActualHeight;

            bool draggingFromStart = startPosition >= itemLength / 2 + DragInitializer.DefaultStartTreshold && startPosition <= itemLength && this.logicalIndex > data.CurrentSourceReorderIndex;
            bool draggingFromEnd   = startPosition <= itemLength / 2 - DragInitializer.DefaultStartTreshold && startPosition >= 0 && this.logicalIndex < data.CurrentSourceReorderIndex;

            bool canReorderColumn = sourceElement != null;

            return(canReorderColumn && (draggingFromStart || draggingFromEnd));
        }
        private bool ShouldReorder(Point position, ReorderItemsDragOperation data)
        {
            if (this.reorderCoordinator == null || data.CurrentSourceReorderIndex == 0)
            {
                return(false);
            }

            var sourceElement = this.reorderCoordinator.Host.ElementAt(data.CurrentSourceReorderIndex);

            if (sourceElement == null)
            {
                return(false);
            }

            var startPosition = this.Owner.Orientation == Orientation.Horizontal ? position.X : position.Y;
            var itemLength    = this.Owner.Orientation == Orientation.Horizontal ? this.ActualWidth : this.ActualHeight;

            return((startPosition >= itemLength / 2 + DragInitializer.DefaultStartTreshold &&
                    startPosition <= itemLength && this.logicalIndex > data.CurrentSourceReorderIndex) ||
                   (startPosition <= itemLength / 2 - DragInitializer.DefaultStartTreshold &&
                    startPosition >= 0 && this.logicalIndex < data.CurrentSourceReorderIndex));
        }