BaconographyWP8.Common.ReorderListBox.dragInterceptor_ManipulationStarted C# (CSharp) Method

dragInterceptor_ManipulationStarted() private method

Called when the user presses down on the transparent drag-interceptor. Identifies the targed drag handle and list item and prepares for a drag operation.
private dragInterceptor_ManipulationStarted ( object sender, System.Windows.Input.ManipulationStartedEventArgs e ) : void
sender object
e System.Windows.Input.ManipulationStartedEventArgs
return void
        private void dragInterceptor_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
        {
            if (this.dragItem != null)
            {
                return;
            }

            if (this.itemsPanel == null)
            {
                ItemsPresenter scrollItemsPresenter = (ItemsPresenter)this.scrollViewer.Content;
                this.itemsPanel = (Panel)VisualTreeHelper.GetChild(scrollItemsPresenter, 0);
            }

            GeneralTransform interceptorTransform = this.dragInterceptor.TransformToVisual(
                Application.Current.RootVisual);
            Point targetPoint = interceptorTransform.Transform(e.ManipulationOrigin);
            targetPoint = ReorderListBox.GetHostCoordinates(targetPoint);

            List<UIElement> targetElements = VisualTreeHelper.FindElementsInHostCoordinates(
                targetPoint, this.itemsPanel).ToList();
            ReorderListBoxItem targetItemContainer = targetElements.OfType<ReorderListBoxItem>().FirstOrDefault();
            if (targetItemContainer != null && targetElements.Contains(targetItemContainer.DragHandle))
            {
                VisualStateManager.GoToState(targetItemContainer, ReorderListBoxItem.DraggingState, true);

                GeneralTransform targetItemTransform = targetItemContainer.TransformToVisual(this.dragInterceptor);
                Point targetItemOrigin = targetItemTransform.Transform(new Point(0, 0));
                Canvas.SetLeft(this.dragIndicator, targetItemOrigin.X);
                Canvas.SetTop(this.dragIndicator, targetItemOrigin.Y);
                this.dragIndicator.Width = targetItemContainer.RenderSize.Width;
                this.dragIndicator.Height = targetItemContainer.RenderSize.Height;

                this.dragItemContainer = targetItemContainer;
                this.dragItem = this.dragItemContainer.Content;
                this.isDragItemSelected = this.dragItemContainer.IsSelected;

                this.dragInterceptorRect = interceptorTransform.TransformBounds(
                    new Rect(new Point(0, 0), this.dragInterceptor.RenderSize));

                this.dropTargetIndex = -1;
            }
        }