Get control in code from ControlTemplate By Name

Posted by Polaris on Stack Overflow See other posts from Stack Overflow or by Polaris
Published on 2010-05-12T05:33:20Z Indexed on 2010/05/12 5:34 UTC
Read the original article Hit count: 160

Filed under:
|
|

Hello. I have next control template in my WPF app.

    <Style TargetType="Label" x:Key="LabelStyle">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Label">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="40"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <TextBox x:Name="MyTextBlock" Text="{TemplateBinding Content}"  Height="20" HorizontalAlignment="Left"  VerticalAlignment="Top" />
                        <Label Content="{TemplateBinding Content}" Grid.Column="1" Grid.Row="1"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

TextBox "MyTextBlock" is invisible in C# code of window. How can I access to this textblock in code

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#