How to align the control in code behind.
XAML:
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="60" />
<RowDefinition />
</Grid.RowDefinitions>
</<Grid>
<TextBlock HorizontalAlignment="Center" Grid.row="0"/>
In code behind, I want to add the DataGrid
in to that Grid.
DataGrid dt = new DataGrid();
// how to add above the grid in to that
// layoutroot in second row.
For second row, set the Grid.Row property as below:
DataGrid dt = new DataGrid();
Grid.SetRow(dt ,1);
LayoutRoot.Children.Add(dt);
You can use Grid.SetRow() and Grid.SetColumn() functions to set positions from code behind.
Grid.SetRow(dt,1); // set position
LayoutRoot.Children.Add(dt); // add control into the Grid
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.