簡體   English   中英

如何在代碼后面進行控制

[英]How to allign control in code behind

如何在后面的代碼中對齊控件。

XAML:

<Grid x:Name="LayoutRoot">
    <Grid.RowDefinitions>
        <RowDefinition Height="60" />
        <RowDefinition />
    </Grid.RowDefinitions>
</<Grid>

<TextBlock HorizontalAlignment="Center" Grid.row="0"/>

在后面的代碼中,我想將DataGrid添加到該Grid中。

DataGrid dt = new DataGrid();

// how to add above the grid in to that 
// layoutroot in second row.

對於第二行,將Grid.Row屬性設置如下:

   DataGrid dt = new DataGrid();
   Grid.SetRow(dt ,1);

   LayoutRoot.Children.Add(dt);

您可以使用Grid.SetRow()和Grid.SetColumn()函數從后面的代碼中設置位置。

Grid.SetRow(dt,1); // set position
LayoutRoot.Children.Add(dt); // add control into the Grid

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM