The87Boy
The87Boy

Reputation: 887

Change grid-settings programmatically

I have a XAML-code that looks like this

<Grid>
   <Grid.RowDefinitions>
      <RowDefinition Height="140"/>
      <RowDefinition Height="*"/>
   </Grid.RowDefinitions>
   <Grid.ColumnDefinitions>
      <ColumnDefinition x:Name="primaryColumn" Width="40*"/>
      <ColumnDefinition Width="50*"/>
   </Grid.ColumnDefinitions>
   <Grid x:Name="titlepanel">
      ...
   </Grid>
   <Grid x:Name="leftgrid" Grid.Row="1">
      ...
   </Grid>
   <Grid x:Name="rightgrid" Grid.Row="0" Grid.Column="1" Grid.RowSpan="2">
      ...
   </Grid>
</Grid>

Is it possible in C# to change the rightgrid so it looks like this

<Grid x:Name="rightgrid" Grid.Row="1" Grid.Column="1">
   ...
</Grid>

I cannot just set in the XAML-code as there are situations, where I need that?
Or do I have to create a new page?

Upvotes: 0

Views: 1881

Answers (1)

mlorbetske
mlorbetske

Reputation: 5649

In the code behind, to unset RowSpan on rightgrid you'd do:

rightgrid.ClearValue(Grid.RowSpanProperty);

Similarly, to set the Row to 1, you'd do:

rightgrid.SetValue(Grid.RowProperty, 1);

From the MSDN:

Upvotes: 4

Related Questions