title: Xaml container for 2D array wpf
body: <p>I am making a chess application in wpf. I am currently creating the UI. This is my first time using WPF and i am a little confused how to bind the 2D array to a suitable xaml container in a simple manner. </p>
  
  <p>For example, this is the code for the UI:</p>
  
  <pre><code>public partial class GameView : Window
  {
      private Game game;
      private const int tableSize = 8;
      ChessCell[,] chessMatrix = new ChessCell[tableSize, tableSize];
      public GameView(bool loadGame)
      {
          InitializeComponent();        
          game = new Game(loadGame);
          GenerateEmptyGrid();
      }
  
      private void GenerateEmptyGrid()
      {   
          for (int i = 0; i &lt; tableSize; i++)
          {               
              for (int j = 0; j &lt; tableSize; j++)
              {
                  chessMatrix[i, j] = new ChessCell();
                  if ((j + i) % 2 == 0)
                  {
                      chessMatrix[i, j]._tileColor = Color.FromRgb(255, 255, 255);
                  }
                  else
                  {
                      chessMatrix[i, j]._tileColor = Color.FromRgb(0, 0, 0);
                  }
              }
          }
  
          chessGrid.ItemsSource = chessMatrix;
      }
  
      public class ChessCell
      {
          public string _piece { get; set; }
          public Color _tileColor { get; set; }
      }
  }
  </code></pre>
  
  <p>This generated the error: <code>System.ArgumentException: 'Array was not a one-dimensional array.'</code></p>
  
  <p>On the line: <code>chessGrid.ItemsSource = chessMatrix;</code></p>
  
  <p>Chess grid is a datagrid:</p>
  
  <p>chessGrid:</p>
  
  <pre><code>  &lt;Grid&gt;
          &lt;DataGrid Name ="chessGrid" SelectionMode="Single" SelectionUnit="Cell"&gt;
  
          &lt;/DataGrid&gt;
   &lt;/Grid&gt;
  </code></pre>
  
  <p>So obviously it accepts only a 1D array. I have looked some but i cant seem to find a xaml container that you can easily bind a 2D array too? Any suggestions on such a container or are there any other simple way to view a 2D array? </p>