tags:

views:

75

answers:

1

New to C# and WPF trying to reproduce a simple 2D chess game written in Java Swing a few years ago. Consists of an 8x8 grid of buttons, produced in a loop similar to:

JButton[][] squares = new JButton[8][8];
grid.setLayout(new GridLayout(8,8));

for (int i = 0; i < squares.length; i++){
 for (int j = 0; j < squares[i].length; j++){
  squares[i][j] = new JButton();
  grid.add(squares[i][j]);
  squares[i][j].addActionListener(this);
 } 
}

Is it possible to do similar in C# using WPF? Any help much appreciated

Thanks, Rob

A: 

You can definitely do this in WPF. Take a look at the Grid and Button controls. You'll need to set the Grid.Row and Grid.Column properties for each button, and you'll need to create 8 entries each in the Grid.RowDefinitions and Grid.ColumnDefinitions lists.

Take a look here, for a good start. (It uses XAML, but you can do it with C# as well.)

John Fisher
WPF has a UniformGrid control that might be easier to use in the case of a chessboard.
mdm20