private void Mouse_Pressed(object sender, MouseEventArgs e) { Border square = (Border)sender; Piece p = null; if (square.Child != null) { ImagePiece img = (ImagePiece)(square.Child); p = img.Piece; } Console.WriteLine("Mouse Pressed: " + p.location); selectedPiece = p; }
public void refreshBoard() { // First step is to clear the board of all old images. clearBoard(); // Now we look at each piece on the board and assign the correct image to the correct square. List <Piece> pieces = game.board.board; foreach (Piece p in pieces) { Image i = new ImagePiece { Source = ImageLoader.getImage(p), Piece = p }; Border square = (Border)VisualTreeHelper.GetChild(grid, (64 - p.location.FlatComputerCoordinate())); square.Child = i; } }