Home > DeveloperSection > Forums > C# XAML How to modify the dimensions of the rows and the columns of a Grid
Simons Hood
Simons Hood

Total Post:70

Posted on    December-23-2013 3:24 AM


 1 Reply(s)
 1168  View(s)
Rate this:

I have the next code in XAML :


        <RowDefinition Height="6*" />

        <RowDefinition Height="*" />


What I want is to modify the code in C#. I'm using the next code :

 ListBoxGrid.RowDefinitions[0].Height = new GridLength(100);

 ListBoxGrid.RowDefinitions[1].Height = new GridLength(800);

Using pixels to set the Height of the rows works just fine, but I would very much like to use the "*"-thing, something like

 ListBoxGrid.RowDefinitions[0].Height = "*";

 ListBoxGrid.RowDefinitions[1].Height = "3*";

How can I do something like that ? I'm thinking that a solution would be to get the Height of the control/page that contains my grid and make :

 ListBoxGrid.RowDefinitions[0].Height = ControlHeight/4;

 ListBoxGrid.RowDefinitions[1].Height = ControlHeight/4*3;

Is there another solution ? More elegant than these operations ? (I will use more than two rows, so it would be nice to not have something very complicated).

Pravesh Singh

Total Post:412

Posted on    December-23-2013 5:15 AM

Hi Samuel,

You can do it, check the other constructors for GridLength

myGrid.RowDefinitions[0].Height = new GridLength(1, GridUnitType.Star);

Don't want to miss updates? Please click the below button!

Follow MindStick