Bui Quang Huy
Bui Quang Huy

Reputation: 1794

Edit Grid.RowDefination programmatically in UWP

As the title, I set the row definition of the grid in XAML file first. But in the code behind I want to change it in some case. So do we have any way to do it? Can we do something like this

grid_socket.SetValue(Grid.ColumnProperty, 0);

Upvotes: 1

Views: 518

Answers (1)

Martin Zikmund
Martin Zikmund

Reputation: 39082

You can access RowHeight properties accessing Grid.RowDefinitions property. For example setting the first row height to 2*:

MyGrid.RowDefinitions[0].Height = new GridLength(2, GridUnitType.Star);

Alternatively you can name a particular row definition:

<Grid.RowDefinitions>
    <RowDefinition x:Name="FirstRow" />
    <RowDefinition />
</Grid.RowDefinitions>

And then access it code via FirstRow directly.

Upvotes: 4

Related Questions