forum

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

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

Anonymous User 2451 23-Dec-2013

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


wpf wpf 
Updated on 23-Dec-2013
I am a content writter !

Can you answer this question?


Answer

1 Answers

Liked By