Creating a HierarchicalDataTemplate in Silverlight with code

1.3k views Asked by At

I'm trying to create a HierarchicalDataTemplate (from the Silverlight Toolkit) in code in Silverlight following this advice on creating DataTemplates from code:

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

There are 1 answers

1
KeithMahoney On BEST ANSWER

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.