开发者

How to add child control to Grid in specific position in code?

开发者 https://www.devze.com 2023-01-24 23:21 出处:网络
Suppose I define a Grid in xaml like: <Grid x:Name=\"LayoutRoot\" Background=\"White\"> <Grid.RowDefinitions>

Suppose I define a Grid in xaml like:

<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>

then I want to add child control to the grid in column=0, row = 1 in code behin开发者_如何学JAVAd.

How to implement it?


Quite a late response but here you go:

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

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

The first parameter is the control you've added to your grid. The second parameter is the column/row position you want to add it to.

0

精彩评论

暂无评论...
验证码 换一张
取 消