TheQuestioner
TheQuestioner

Reputation: 447

C# XAML How to modify the dimensions of the rows and the columns of a Grid

I have the next code in XAML :

    <Grid.RowDefinitions>
        <RowDefinition Height="6*" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>

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).

Upvotes: 0

Views: 118

Answers (1)

Kevin DiTraglia
Kevin DiTraglia

Reputation: 26078

You can do it, check the other constructors for GridLength

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

Upvotes: 2

Related Questions