0

假设我有一个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运行时?

4

1 回答 1

2

试试这个 :

    TextBlock MyTextBlock = New TextBlock();
    Grid.SetRow( MyTextBlock, 1 );
    Grid.SetColumn( MyTextBlock, 2 );
    grid1.Children.Add( MyTextBlock );
于 2013-01-22T12:45:14.203 回答