ailon's DevBlog: Development related stuff in my life

Name scopes within templates are not supported

5/8/2009 3:03:59 PM

I’ve got an issue reported on amCharts for WPF forum suggesting that it’s impossible to use the charts in DataTemplate. I’ve verified that it was true and exception message reads as follows:

"NameScopeProperty found within the content of a FrameworkTemplate, on a 'AmCharts.Windows.LineChart' object. Name scopes within templates are not supported."

The exception was caused by the call to SetNameSpace method in the constructor of the chart base class:

NameScope.SetNameScope(this, new NameScope());

I’ve re-read documentation on name scopes and made an assumption that I have to find a way to use template’s own name scope to register my names with it and…  spent almost a day trying to figure out how to do it universally.

Finally I gave up on that branch of thought and decided to try something else. To my surprise the problem was solved by simply moving the same call to SetNameScope() from constructor to a place right before it is needed. Namely where I make the first call to RegisterName() which happens after my controls have been loaded, templates applied, etc.

Now I’m not completely sure why this worked but my understanding is that if you do it in the constructor SetNameScope() get’s called in the context of the Template (producing an exception above) and when it is called later it’s already in context of the control to which the Template is applied. Please, correct me if I’m wrong.

kick it on Shout it

Tags: ,

blog comments powered by Disqus
Copyright © 2003 - 2018 Alan Mendelevich
Powered by BlogEngine.NET