NullReferenceException calls RegisterName () from control in DataTemplate
I created my own WPF control that does some animations on dynamically created objects. I am using SetTargetName () to set the target of the animation. (I know about SetTarget (), but I need to support .NET 3.5 without SP1.) Obviously, before that I need to register the object names with RegisterName (). Everything works fine when my control is usually placed as an object in a window or on a page.
But when I add my control to the DataTemplate, I get a NullReferenceException when I call RegisterName ().
The top of the stack trace looks like this:
at System.Windows.TemplateNameScope.System.Windows.Markup.INameScope.RegisterName (row name, scopedElement object)
at System.Windows.FrameworkElement.RegisterName (row name, scopedElement object)
Both parameters I pass to RegisterName are not null and the object I am calling it on is not null. So something else must be null internally and I don't know what to do about it. There is also no information about TemplateNameScope.
Any pointers are much appreciated.
a source to share