At the point the binding is being evaluated the complete visual tree is not build yet.
That is why template is not available.
In order to fix this you will have to call cp.ApplyTemplate
or postpone the code to be executed when UI thread is in background by using Dispatcher.BeginInvoke()
.