假设我有grid
,
<Grid Name="grid1">
<Grid.ColumnDefinitions>
<ColumnDefinition Name="col1" Width="auto">
</ColumnDefinition>
<ColumnDefinition Name="col2" Width="380">
</ColumnDefinition>
<ColumnDefinition Name="col3" Width="auto">
</ColumnDefinition>
<ColumnDefinition Name="col4" Width="200">
</ColumnDefinition>
</Grid.ColumnDefinition>
<Grid.RowDefinitions>
<RowDefinition Name="row1" Height="2*">
</RowDefinition>
<RowDefinition Name="row2" Height="2*">
</RowDefinition>
</Grid.RowDefinitions>
<Grid>
这是2
行和4
列。我需要在我的代码后面的TextBlock
和Grid.Row="1"
中创建Grid.Column="2"
。
如何在相应的Grid
行和列中创建它,并将绑定设置为
myTextBlock1.SetBinding(TextBlock.TextProperty, (new Binding("SelectedItem." + dataGrid1.Columns[5].Header)
{ ElementName = "dataGrid1" }));
在运行时到textblock
?
答案 0 :(得分:2)
试试这个:
TextBlock MyTextBlock = New TextBlock();
Grid.SetRow( MyTextBlock, 1 );
Grid.SetColumn( MyTextBlock, 2 );
grid1.Children.Add( MyTextBlock );