private void RenderBoard() { BoardGrid.Children.Clear(); Board.Clear(); for (int i = 0; i < 8; i++) { Board.Add(new List <Rectangle>()); } for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { var rect = new Rectangle() { VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch, Tag = $"{j}{7 - i}", }; rect.MouseLeftButtonDown += Board_MouseLeftButtonDown; rect.MouseLeftButtonUp += Board_MouseLeftButtonUp; rect.MouseRightButtonDown += Board_MouseRightButtonDown; BoardGrid.Children.Add(rect); if ((i + j) % 2 == 0) { rect.Fill = new SolidColorBrush(Color.FromRgb(238, 238, 210)); } else { rect.Fill = new SolidColorBrush(Color.FromRgb(118, 150, 86)); } Board[i].Add(rect); Grid.SetRow(rect, i); Grid.SetColumn(rect, j); } } RenderCoordinates(); }