DragStartingContext IDragDropElement.DragStarting(DragDropTrigger trigger, object initializeContext)
        {
            var dragVisual = this.ParentGrid.DragBehavior.GetReorderVisual(this);

            if (dragVisual == null)
            {
                DataGridFlyoutHeader header = this.CreateHeader();

                dragVisual = header;
            }

            // TODO: Consider exposing this through separate control.
            dragVisual.DataContext = this.DataContext;
            this.Opacity           = 0.0;

            var surface = this.OnDragSurfaceRequested();

            var payload = new ReorderItemsDragOperation(this);

            this.ParentGrid.DragBehavior.OnReorderStarted(this.DataContext as GroupDescriptorBase);

            return(new DragStartingContext {
                DragVisual = dragVisual, Payload = payload, DragSurface = surface, HitTestStrategy = new ColumnHeaderHittestStrategy(this, surface.RootElement)
            });
        }
        private bool ShouldReorder(Point position, ReorderItemsDragOperation data)
        {
            if (this.reorderCoordinator == null)
            {
                return(false);
            }

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

            bool draggingFromRight = position.X >= this.ActualWidth / 2 + DragInitializer.DefaultStartTreshold && position.X <= this.ActualWidth && this.logicalIndex > data.CurrentSourceReorderIndex;
            bool draggingFromLeft  = position.X <= this.ActualWidth / 2 - DragInitializer.DefaultStartTreshold && position.X >= 0 && this.logicalIndex < data.CurrentSourceReorderIndex;

            bool canReorderColumn = sourceElement != null && this.Owner.DragBehavior.CanReorder(sourceElement.Column, this.Column);

            return(canReorderColumn && (draggingFromLeft || draggingFromRight));
        }