I have set ColumnDefinitions
in XAML like:
<Grid x:Name="MainGrid" Background="#FF256BD1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
...
</Grid>
In the code behind I'm adding a StackPanel
as children in the MainGrid
like:
MainGrid.Children.Add(stackPanel);
How to put this stackPanel in the First Column in Code behind like we do in XAML as: Grid.Column="0"
or Grid.ColumnSpan="2"
or Grid.Row="1"
, etc.
You can make use of the SetRow
, SetColumn
, SetColumnSpan
Methods:
Grid.Children.Add(stackPanel);
Grid.SetRow(stackPanel, 1);
Grid.SetColumn(stackPanel, 0);
Grid.SetColumnSpan(stackPanel, 2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With