private void handleCellClick(object sender, RoutedEventArgs e) { if (readOnlyMode) { return; // no click events if board is readonly } PieceView pv = (PieceView)sender; RaiseBoardCellClickEvent(pv.getCol(), pv.getRow()); }
public void setupTable() { int bheight = board.getHeight(); int bwidth = board.getWidth(); if (this.testMode) { this.setupTestBoard(); } BoardGrid.Children.Clear(); BoardGrid.ColumnDefinitions.Clear(); BoardGrid.RowDefinitions.Clear(); //--- Create rows and columns and size them to equally divide the space. for (int i = 0; i < bwidth; i++) { ColumnDefinition cd = new ColumnDefinition(); cd.Width = new GridLength(1, GridUnitType.Star); BoardGrid.ColumnDefinitions.Add(cd); } for (int i = 0; i < bheight; i++) { RowDefinition rd = new RowDefinition(); rd.Height = new GridLength(1, GridUnitType.Star); BoardGrid.RowDefinitions.Add(rd); } //--- Now create the cells, each of them a Game Piece. for (int r = 0; r < bheight; r++) { for (int c = 0; c < bwidth; c++) { PieceView pv = new PieceView(); pv.setCol(c); pv.setRow(r); pv.setPiece(board.getCell(c, r)); pv.Click += handleCellClick; Grid.SetRow(pv, r); Grid.SetColumn(pv, c); //ContentControl bv = new ContentControl(); //bv.Content = c + "," + r; //Grid.SetRow(bv, r); Grid.SetColumn(bv, c); BoardGrid.Children.Add(pv); } } }