0

Let say I have a 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>

That is 2 rows and 4 columns. I need to create a TextBlock in Grid.Row="1" and Grid.Column="2" from my code behind.

How can I create it in corresponding Grid row and column and set binding as

  myTextBlock1.SetBinding(TextBlock.TextProperty, (new Binding("SelectedItem." + dataGrid1.Columns[5].Header) 
     { ElementName = "dataGrid1" }));

to that textblock in run-time?

1 Answer 1

2

Try This :

    TextBlock MyTextBlock = New TextBlock();
    Grid.SetRow( MyTextBlock, 1 );
    Grid.SetColumn( MyTextBlock, 2 );
    grid1.Children.Add( MyTextBlock );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.