Accessing Silverlight Control template items codebehind

1.6k Views Asked by At

I have a control template in page Layout as following.

<Grid x:Name="LayoutRoot">
        <Grid.Resources>
        <ControlTemplate x:Key="myTemplate" TargetType="esri:MapTip">
                <Border CornerRadius="10" Background="#DDFFEEEE" BorderThickness="4" BorderBrush="#99FF0000">
                    <StackPanel Background="#DDFFFFFF">

                      <sdk:TabControl Height="180" Margin="5"  Name="tabControl1"  Width="300">      
                               <sdk:TabItem Header="Info" Name="infoTab">

                               <TextBlock x:Name="cityInfoTxt" Tag="{Binding [City_ID]}"/>    

                               </sdk:TabItem>
                        </sdk:TabControl>
                    </StackPanel>
                </Border>
            </ControlTemplate>

In code behind how can I access the ??

I tried this,

private void button1_Click(object sender, RoutedEventArgs e)
{
    var te = this.LayoutRoot.Resources["myTemplate"] as ControlTemplate;

}

but can not access the textblock in the tab control.

1

There are 1 best solutions below

0
Vinicius On

override the method OnAplyTemplate() on code behind and try to find your component.

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        var myTextBlock = GetTemplateChild("cityInfoTxt") as TextBlock;
    }

Hope it helps