如何在代码中的特定位置添加子控件到Grid?

时间:2010-11-15 14:40:19

标签: silverlight-4.0

假设我在xaml中定义了一个Grid:

<Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition  Width="*"/>
        </Grid.ColumnDefinitions>       
    </Grid>

然后我想将子控件添加到列= 0的网格中,代码后面的行= 1。

如何实施?

1 个答案:

答案 0 :(得分:0)

很晚才回复,但是你去了:

Grid.SetRow(yourControl, 1);
Grid.SetColumn(yourControl, 1);

Grid.SetRow(otherControl, 0);
Grid.SetColumn(otherControl, 0);

第一个参数是您添加到网格中的控件。第二个参数是您要将其添加到的列/行位置。