tags:

views:

9

answers:

1

In my prism module, I have the following code snippet:

        using (var manifestResourceStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("MyAssembly.CaseHost.ViewModelDataTemplates.xaml"))
        {
            ParserContext context = new ParserContext();
            context.XmlnsDictionary.Add("local", "clr-namespace:MyAssembly.CaseHost");
            var resourceDictionary = (ResourceDictionary)XamlReader.Load(manifestResourceStream, context);
            _resourceRegistry.Add(resourceDictionary);
        }

I'm basically trying to load up this very simple ResourceDictionary:

<DataTemplate DataType="{x:Type local:PlayPauseViewModel}">
    <Label>Look mom!</Label>
</DataTemplate>

This gives me the following exception:

Type reference cannot find public type named 'PlayPauseViewModel'.

This is a cpp/winforms/wpf application beast, so I can't use URI's. How can I solve this?

A: 

Found it!

The problem was how the namespace was specified in the DataTemplate:

Standard definition (did not work):

xmlns:local="clr-namespace:<Namespace>"

More explicit definition (worked!)

xmlns:local="clr-namespace:<Namespace>;assembly=<assembly>"

Replace <> with namespace and assembly.

Marius