If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Error in finding an element in a DataTemplate

I am having an ItemsControl with a DataTemplate to show a collection of object. I add object to collection at run time. After adding an object, I want to set focus to a textbox in the recently added object's template. I do this by trying to find out the textbox immediately after adding the object with the code below.

I am getting the following error in the FindName in the third line.
{"This operation is valid only on elements that have this template applied."}

The status of ItemContainerGenerator is ContainersGenerated.
This works if I have the same code somewhere else like for example on editing some control after the object is added or somethign like that.
So I am just wondering if there is some problem in immediately finding the element, somthing like the control is not loaded or soemthing?

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.