Пример #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();
        }