Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Grids In codeBehind

To divide a Grid into rows we give it row definitions and the UIElement that needs to be placed in a particular row in that grid we do it like this:

Button Name="Button1" Grid.Row="1"

Now suppose I want to do this thing in code behind dynamically then how can we do it.

Thank You.

like image 347
user1512186 Avatar asked Jul 09 '26 07:07

user1512186


1 Answers

If you want to create a Button in code and add to specific cell of the Grid then you can do it like this:

var myButton = new Button();
myButton.Content = "myButton";
Grid.SetColumn(myButton, 1);
Grid.SetRow(myButton, 1);
myGrid.Children.Add(myButton);
like image 168
dkozl Avatar answered Jul 11 '26 21:07

dkozl