title: WPF: How to dynamically create a grid with x rows and y columns with consecutive numbers
body: <p>I am completely new to wpf and c#, so excuse if this is super trivial question. I am trying to create a fairly simple control.</p>
  
  <p><a href="https://i.stack.imgur.com/VTW5l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VTW5l.png" alt="grid"></a></p>
  
  <p>This grid will always have consecutive numbers, with a color rectangle in front of it. Clicking on the gray rectangle will change its color, and set the text to bold (I will deal with these triggers later).</p>
  
  <p>For now, I just need to figure out how to create this control dynamically. When the program starts, it needs to one time create this control, and then the size won't change. I need to tell it the number of columns and rows (each column will probably always have 8 elements), and have it populate with consecutive numbers with specific font style/rectangle color.</p>
  
  <p>I was experimented with creating a stackpanel UserControl for rectangle/label combo, passing the style to it, and then adding 32 of these UserControls in specific row/column in a grid. But I would need the size of that grid to be dynamic, so I need some for loop in the code I think.</p>
  
  <p>Thanks!</p>