views:

69

answers:

1

I don't know why but for some reason I am not able to refer to my tbText control in my code behind file. Here is the XAML part:

        <ComboBox.ItemTemplate>
            <DataTemplate>
                <ItemsControl x:Name="ic">

                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                            <ColumnDefinition Width="2*"></ColumnDefinition>
                        </Grid.ColumnDefinitions>

                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"></RowDefinition>
                        </Grid.RowDefinitions>
                    </Grid>                                                

                     **<TextBlock x:Name="tbText"  Grid.Column="0" Grid.Row="0"  Margin="10" />**
                     <Image Grid.Column="1" Margin="10" Grid.Row="0" Width="100" Height="100" Stretch="Fill">

                    </Image>                                                  


                </ItemsControl>
            </DataTemplate>
        </ComboBox.ItemTemplate>

I cannot refer to the "tbText" control.

+5  A: 

You can't refer to it because it is inside an Items control.

You'd have to search the ItemsControl children in order to find the textbox.

See Finding control within wpf items control for ways to do this.

Brandon