Xaml – Add and Update Row Definitions

XAML-LOGO Row and Column Definitions are used to set the rows and columns in a grid on a xaml page. I wanted to add or remove any of these definitions from the code behind using C#. Next is the solution:

Add Row Definitions:

RowDefinitionCollection defs = myGrid.RowDefinitions;
defs.Add(newRowDefinition(){Height=newGridLength(140)});
defs.Add(newRowDefinition(){Height=newGridLength(1,GridUnitType.Star)});

Update Row Definitions:

RowDefinitionCollection defs = myGrid.RowDefinitions;
defs[0] = newRowDefinition(){Height=newGridLength(140)};
defs[1] = newRowDefinition(){Height=newGridLength(1,GridUnitType.Star)};

 

To add and update columns, just change RowDefinition with ColumnDefinition in the above code. Hope this helps you in your Windows Phone and Windows Store apps! Happy Xamling!

Hello, nice to meet you

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Leave a Reply