// Determines the index that the dragged item would occupy when dropped private int GetDragIndex() { double dragLocation = _dragImage.GetRelativePosition(_todoList).Y + _scrollViewer.VerticalOffset + _dragImage.ActualHeight / 2; int dragIndex = (int)(dragLocation / _dragImage.ActualHeight); dragIndex = Math.Min(_todoItems.Count - 1, dragIndex); return(dragIndex); }
// Determines the index that the dragged item would occupy when dropped private int GetDragIndex() { System.Windows.Point relativePosition = _dragImage.GetRelativePosition(this.interactionListControl); Debug.WriteLine("DragReOrderInteraction. RelativePosition {0}, scrollViewer Vertical offset {1}, dragImage height {2}", relativePosition.Y, _scrollViewer.VerticalOffset, _dragImage.ActualHeight); double dragLocation = relativePosition.Y + _scrollViewer.VerticalOffset + _dragImage.ActualHeight / 2; Debug.WriteLine("Drag location {0}", dragLocation); int dragIndex = 0; double offset = 0; if (this.interactionList != null) { for (int i = 0; i < this.interactionList.Count; i++) { var container = this.interactionListControl.ItemContainerGenerator.ContainerFromItem(this.interactionList[i]); var taskPanel = FindNamedDescendant <StackPanel>(container, "TaskStackPanel"); offset += taskPanel.ActualHeight; Debug.WriteLine("item {0}, height {1}, offset so far {2}", i, taskPanel.ActualHeight, offset); dragIndex++; if (offset > dragLocation) { break; } } } //int dragIndex = (int)(dragLocation / _dragImage.ActualHeight); Debug.WriteLine("Drag index {0}", dragIndex); dragIndex = Math.Min(this.interactionList.Count - 1, dragIndex); if (dragIndex <= 0) { dragIndex = 1; } if (this.interactionList[dragIndex].IsPullDown) { dragIndex++; } return(dragIndex); }