tags:

views:

195

answers:

1

Using the Silverlight 3 Release, I created a Silverlight UserControl that contains a DataPager and a DataGrid. I modified the DataPager ControlTemplate and added a TextBox with an x:Name of TestTextBox inside the DataPager's Border right before the standard DataPager buttons, but I can't seem to get a reference to that TextBox in the UserControl code behind.

In the code behind (C#), I tried: TextBox myTextBox = this.GetTemplateChild("TestTextBox") as TextBox, but myTextBox winds up null. I suspect I need to operate against the DataPager instance, but I don't see any methods for drilling into the DataPager's child controls.

I don't have much experience with ControlTemplates so I'm not exactly sure how to phrase the issue well enough to turn up anything useful searching here and the other usual resources. Can someone nudge me in the right direction?

A: 

I guess you're looking for FindControl("name")? Try it out:

TextBox tb = DataPager1.FindControl("TestTextBox") as TextBox;

At least that's how it rolls in ASP-NET, when you have a control inside a template or something and you can't access it directly.

ANeves