示例#1
0
        private void OnSquarePointerPressed(object sender, PointerRoutedEventArgs e)
        {
            if (!HasDragAndDrop)
            {
                return;
            }

            dragStartPoint     = e.GetCurrentPoint(board).Position;
            pointerPressSquare = (SquareView)sender;
        }
示例#2
0
        private void MoveDropHintEllipseToSquare(SquareView square)
        {
            if (dropHintEllipse == null)
            {
                throw new InvalidOperationException("The drop hint ellipse should not be null.");
            }

            SquareViewModel squareVM          = (SquareViewModel)square.DataContext;
            Point           squareMiddlePoint = GetSquareMiddlePoint(squareVM.Coordinate);

            Canvas.SetTop(dropHintEllipse, squareMiddlePoint.Y - dropHintEllipse.Height / 2);
            Canvas.SetLeft(dropHintEllipse, squareMiddlePoint.X - dropHintEllipse.Width / 2);
        }
示例#3
0
        private void EndDragMove()
        {
            if (!isDragStarted)
            {
                return;
            }

            dragCanvas.Children.Clear();

            isDragStarted = false;

            dragSourcePieceViewModel.IsDragSource = false;
            dragSourcePieceViewModel = null;
            pointerPressSquare       = null;
            dropHintEllipse          = null;
        }
示例#4
0
        private void OnSquarePointerReleased(object sender, PointerRoutedEventArgs e)
        {
            if (isDragStarted)
            {
                SquareView dropSquare = (SquareView)sender;
                dropSquare.IsDropTarget = false;
                ViewModel.OnPieceDropped((SquareViewModel)dropSquare.DataContext);

                // make sure to re-layout possible changed pieces
                // when a piece changes its coordinate it does not change view arrange
                if (promotionTask == null)
                {
                    piecesItemsControl.ItemsPanelRoot.InvalidateArrange();
                }
            }

            EndDragMove();
        }