public static int GetInsertionIndex(SceneElement container, Point position, out bool isCursorAtEnd)
        {
            isCursorAtEnd = false;
            IViewPanel viewPanel = MoveStrategy.GetContainerHost(container) as IViewPanel;

            if (viewPanel == null)
            {
                return(0);
            }
            Orientation orientation = viewPanel.Orientation;

            if (viewPanel.ChildrenCount == 0)
            {
                return(0);
            }
            bool flag = PlatformTypes.StackPanel.IsAssignableFrom((ITypeId)container.Type) || PlatformTypes.VirtualizingStackPanel.IsAssignableFrom((ITypeId)container.Type);
            ActualBoundsInParent actualBoundsInParent = new ActualBoundsInParent(container);

            foreach (FlowPanelLayoutUtilities.LineInfo line in FlowPanelLayoutUtilities.ExtractLines(container))
            {
                if (flag || FlowPanelLayoutUtilities.IsPointInLine(position, line, orientation))
                {
                    if (line.StartElementIndex == line.EndElementIndex)
                    {
                        IViewVisual child = viewPanel.GetChild(line.StartElementIndex);
                        Rect        elementLayoutBounds = actualBoundsInParent[child];
                        if (FlowPanelLayoutUtilities.DoesPointLieBeforeElement(position, elementLayoutBounds, orientation))
                        {
                            isCursorAtEnd = false;
                            return(line.StartElementIndex);
                        }
                        isCursorAtEnd = true;
                        return(line.StartElementIndex + 1);
                    }
                    IViewVisual child1 = viewPanel.GetChild(line.StartElementIndex);
                    IViewVisual child2 = viewPanel.GetChild(line.EndElementIndex);
                    Rect        elementLayoutBounds1 = actualBoundsInParent[child1];
                    Rect        elementLayoutBounds2 = actualBoundsInParent[child2];
                    if (FlowPanelLayoutUtilities.DoesPointLieBeforeElement(position, elementLayoutBounds1, orientation))
                    {
                        isCursorAtEnd = false;
                        return(line.StartElementIndex);
                    }
                    if (FlowPanelLayoutUtilities.DoesPointLieAfterElement(position, elementLayoutBounds2, orientation))
                    {
                        isCursorAtEnd = true;
                        return(line.EndElementIndex + 1);
                    }
                    for (int startElementIndex = line.StartElementIndex; startElementIndex < line.EndElementIndex; ++startElementIndex)
                    {
                        IViewVisual child3 = viewPanel.GetChild(startElementIndex);
                        IViewVisual child4 = viewPanel.GetChild(startElementIndex + 1);
                        Rect        currentElementLayoutBounds = actualBoundsInParent[child3];
                        Rect        nextElementLayoutBounds    = actualBoundsInParent[child4];
                        if (FlowPanelLayoutUtilities.DoesPointLieBetweenElements(position, currentElementLayoutBounds, nextElementLayoutBounds, orientation))
                        {
                            return(startElementIndex + 1);
                        }
                    }
                    break;
                }
            }
            if (flag)
            {
                return(-1);
            }
            isCursorAtEnd = true;
            return(viewPanel.ChildrenCount);
        }