Catrobat.IDE.WindowsPhone.Controls.ListsViewControls.CatrobatListView.CatrobatListViewMisc.CatrobatListViewWorker.RearrangeRolbi C# (CSharp) Method

RearrangeRolbi() private method

private RearrangeRolbi ( double setYTo ) : void
setYTo double
return void
        private void RearrangeRolbi(double setYTo)
        {
            int actIndex = Items.IndexOf(_tmpDragContentControl);
            CatrobatListViewItem tmpItem;
            Rect itemsBounds;
            if (actIndex > 0)
            {
                tmpItem = (this.ContainerFromIndex(actIndex - 1) as CatrobatListViewItem);
                if (tmpItem == null)
                {
                    return;
                }
                if (tmpItem.Visibility == Visibility.Collapsed)
                {
                    if (tmpItem.Content is BlockEndBrick)
                    {
                        tmpItem = ContainerFromItem((tmpItem.Content as BlockEndBrick).Begin) as CatrobatListViewItem;
                    }

                }
                itemsBounds =
                    tmpItem.TransformToVisual(_scrollViewer)
                        .TransformBounds(new Rect(0.0, 0.0, tmpItem.ActualWidth, tmpItem.ActualHeight));

                if (setYTo < (itemsBounds.Top - _verticalItemMargin) + tmpItem.ActualHeight / 2)
                {
                    MoveItem(Items.IndexOf(tmpItem.Content)/*actIndex - 1*/, actIndex);
                    return;
                }
            }

            tmpItem = (this.ContainerFromIndex(actIndex + 1) as CatrobatListViewItem);
            if (tmpItem == null)
            {
                return;
            }

            itemsBounds = tmpItem.TransformToVisual(_scrollViewer).TransformBounds(new Rect(0.0, 0.0, tmpItem.ActualWidth, tmpItem.ActualHeight));
            if (setYTo > (itemsBounds.Bottom - _verticalItemMargin) - tmpItem.ActualHeight / 2)
            {
                if (tmpItem.IsGrouped)
                {
                    tmpItem = ContainerFromItem((tmpItem.Content as BlockBeginBrick).End) as CatrobatListViewItem;
                }
                MoveItem(Items.IndexOf(tmpItem.Content), actIndex);
            }

        }