How do I get a reference to a TextBox that’s only defined inside a DataTemplate (assuming that I’ve just applied this DataTemplate to some cell in a grid).
So far I’m using the sender in the TextBox events to retrieve this.
Thanks,
rui
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
For getting the reference of a control inside a Data Template, handling the event and then using the sender is one of the available option. There is one more option that you can try:
in .xaml:
in .xaml.cs
Hope this helps!!
Edit:
if you want to use x:Name then also you need to at least get the ContentPresenter and for getting ContentPresenter you need to go through the element tree. The updates you need to make are:
in .xaml:
in .xaml.cs
Hope this helps!!