views:

563

answers:

1

I'm trying to create a HierarchicalDataTemplate (from the Silverlight Toolkit) in code in Silverlight following this advice on creating DataTemplates from code: http://stackoverflow.com/questions/59451/creating-a-silverlight-datatemplate-in-code. However, I haven't been able to get it to work for HierarchicalDataTemplate.

I tried using XamlBuilder that ships with Silverlight Toolkit, but that gives me an error. I've tried XamlReader, and have included various default and prefixed namespaces, but with no luck.

If I run XamlBuilder's Build method, I get the following string:

<HierarchicalDataTemplate xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\" xmlns:attached=\"clr-namespace:MyStuff;assembly=MyStuff\" xmlns=\"clr-namespace:System.Windows;assembly=System.Windows.Controls\"><attached:MyUserControl /></HierarchicalDataTemplate>

The error I get is:

AG_E_PARSER_NAMESPACE_NOT_SUPPORTED

+1  A: 

With the Silverlight Xaml parser, the default xmlns must be "http://schemas.microsoft.com/winfx/2006/xaml/presentation", even if you don't use it. So add that xmlns declaration to your Xaml string, and change the System.Windows clr-namespace declaration to use some prefix.

KeithMahoney
Thanks, Keith. Hopefully the Silverlight Toolkit folks will update XamlBuilder so it does this correctly.
Dan Vanderboom