protected override void OnRender(DrawingContext drawingContext)
{
var itemsControl = DropInfo.VisualTarget as ItemsControl;
if (itemsControl != null)
{
// Get the position of the item at the insertion index. If the insertion point is
// to be after the last item, then get the position of the last item and add an
// offset later to draw it at the end of the list.
ItemsControl itemParent;
if (DropInfo.VisualTargetItem != null)
{
itemParent = ItemsControl.ItemsControlFromItemContainer(DropInfo.VisualTargetItem);
}
else
{
itemParent = itemsControl;
}
var index = Math.Min(DropInfo.InsertIndex, itemParent.Items.Count - 1);
var lastItemInGroup = false;
var targetGroup = DropInfo.TargetGroup;
if (targetGroup != null && targetGroup.IsBottomLevel &&
DropInfo.InsertPosition.HasFlag(RelativeInsertPosition.AfterTargetItem))
{
var indexOf = targetGroup.Items.IndexOf(DropInfo.TargetItem);
lastItemInGroup = indexOf == targetGroup.ItemCount - 1;
if (lastItemInGroup && DropInfo.InsertIndex != itemParent.Items.Count)
{
index--;
}
}
var itemContainer = (UIElement) itemParent.ItemContainerGenerator.ContainerFromIndex(index);
if (itemContainer != null)
{
var itemRect = new Rect(itemContainer.TranslatePoint(new Point(), AdornedElement),
itemContainer.RenderSize);
Point point1, point2;
double rotation = 0;
if (DropInfo.VisualTargetOrientation == Orientation.Vertical)
{
if (DropInfo.InsertIndex == itemParent.Items.Count || lastItemInGroup)
{
itemRect.Y += itemContainer.RenderSize.Height;
}
point1 = new Point(itemRect.X, itemRect.Y);
point2 = new Point(itemRect.Right, itemRect.Y);
}
else
{
var itemRectX = itemRect.X;
if (DropInfo.VisualTargetFlowDirection == FlowDirection.LeftToRight &&
DropInfo.InsertIndex == itemParent.Items.Count)
{
itemRectX += itemContainer.RenderSize.Width;
}
else if (DropInfo.VisualTargetFlowDirection == FlowDirection.RightToLeft &&
DropInfo.InsertIndex != itemParent.Items.Count)
{
itemRectX += itemContainer.RenderSize.Width;
}
point1 = new Point(itemRectX, itemRect.Y);
point2 = new Point(itemRectX, itemRect.Bottom);
rotation = 90;
}
drawingContext.DrawLine(m_Pen, point1, point2);
DrawTriangle(drawingContext, point1, rotation);
DrawTriangle(drawingContext, point2, 180 + rotation);
}
}
}