C# XAML HOW TO MODIFY THE DIMENSIONS OF THE ROWS AND THE COLUMNS OF A GRID

Simons Hood

Total Post:70

Points:494
Posted by  Simons Hood
WPF 
WPF
 1247  View(s)
Ratings:
Rate this:

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

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: C# XAML How to modify the dimensions of the rows and the columns of a Grid

    Hi Samuel,


    You can do it, check the other constructors for GridLength

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

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!