Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top