How to add wpf control to particular grid row and cell during runtime? How to add wpf control to particular grid row and cell during runtime? wpf wpf

How to add wpf control to particular grid row and cell during runtime?


The Grid.Row and Grid.Column properties are Attached Properties, and as such are not set like normal .net properties. The right way to set them from code is:

Grid.SetRow(someLabel, 0);Grid.SetColumn(someLabel, 0);

You should be able to do this before or after adding them to the Grid object's Children collection, but setting them before adding the control should prevent any possible flickering.


  • Create the grid (<yourGrid>) and the Row Definitions like you have done.
  • Create The Control (<yourcontrol>). Then Set The ColumnSpan and Row for the Grid:

    Grid.SetColumnSpan(<yourControl>, 3);Grid.SetRow(<yourControl>, 0);

  • Then add your control to the grid you have created

    <yourGrid>.Children.Add(<yourControl>);