Reputation: 1794
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
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