/// <summary> /// Creates a matrix including the visual representation /// </summary> public void CreateMatrix(Tuple <int, int> matrixSize) { size = matrixSize; rows = new MatrixRow[size.Item2]; // Clear the grid to make sure nothing is left over grid.Children.Clear(); grid.ColumnDefinitions.Clear(); grid.RowDefinitions.Clear(); // Resize grid.Width = elementSize * size.Item1; grid.Height = elementSize * size.Item2; // Create collumns and rows for (int i = 0; i < size.Item1; i++) { ColumnDefinition column = new ColumnDefinition(); grid.ColumnDefinitions.Add(column); } for (int i = 0; i < size.Item2; i++) { RowDefinition row = new RowDefinition(); row.Height = new GridLength(elementSize); grid.RowDefinitions.Add(row); rows[i] = new MatrixRow(size.Item1); } // Iterate through the matrix for (int row = 0; row < rows.Length; row++) { for (int column = 0; column < rows[row].LEDs.Length; column++) { // Create visual representation of the LED Ellipse ellipse = new Ellipse(); ellipse.Stroke = new SolidColorBrush(Colors.Black); // Create the "back-end" of the LED LED led = new LED(this, ellipse, row); rows[row].LEDs[column] = led; // Assign the ellipse to the grid Grid.SetColumn(ellipse, column); Grid.SetRow(ellipse, row); grid.Children.Add(ellipse); } } }
public MatrixRow(int size) { LEDs = new LED[size]; }