Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have the following ControlTemplate:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ControlTemplate x:Key="ComponentTemplate" x:Name="componentTemplate">
        <Border BorderBrush="Black" BorderThickness="2,2,2,2" Width="104" Height="44" CornerRadius="8,8,8,8">
            <Canvas>
                <Rectangle Name="tplRect" Width="100" Height="40" Fill="LightCyan" RadiusX="8" RadiusY="8" />
                <TextBox Name="tplTextBox"  Text="Component" HorizontalAlignment="Center" Margin="17,10"/>
            </Canvas>
        </Border>
    </ControlTemplate>
</ResourceDictionary>




I want to be able to access the textbox in C# code, how would I go about doing that?
Posted

1 solution

That depends, what are you willing to do with the TextBox? With you are willing to access the Text value of it its fairly simple, you only need to bind it to a property from a class.


If you are willing to access other properties of it, I would create an attached property that mark the TextBox for use elsewhere, so in the TextBox you would add the AP and in the PropertyChangedCallback add a custom logic to keep the reference to it.


Hope this helps, if doesn't tell me and I will try to help you out.


All best


Raul

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900