kaliba
kaliba

Reputation: 230

ResourceDictionary can't find DataType for the DataTemplate

I have to outsource my DataTemplates to a ResourceDictionary. Everything works fine, except detecting the DataTypes of the DataTemplates.

In order to get the ResourceDictionary I wrote following function:

public static ResourceDictionary ParseResourceDictionary(String path)
{
        System.Windows.ResourceDictionary templates = new System.Windows.ResourceDictionary();
        templates = new System.Windows.ResourceDictionary() { Source = new System.Uri(path) };
        return templates;
}

My ResourceDictionary looks like that:

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:classes="clr-namespace:ResourceDictTest;assembly=ResourceDictTest"
>

<DataTemplate DataType="{x:Type classes:Company}">
    <TextBlock Text="{Binding Name}"/>
</DataTemplate>

If I get the dictionary via my function, I got the exception, that the DataType "Company" can't be found in classes, but when I write "classes:" Company will get suggested, so the namespace isn't wrong at all.

The error message would be something like that (not my native language):

No public type with the name "Company" can be found.

And yes, the class "Company" is set to public.

Before this, I tried:

xmlns:classes="clr-namespace:ResourceDictTest"

Instead of this:

xmlns:classes="clr-namespace:ResourceDictTest;assembly=ResourceDictTest"

And got the message, that there was an error creating a Type out of "classes:Company".

Can anyone give me a hint?

Upvotes: 2

Views: 747

Answers (1)

Ian
Ian

Reputation: 323

Have you tried getting the ResourceDictionary via XAML?

<Application.Resources>
    <ResourceDictionary Source="Resources/ResourceDictTest.xaml" />
</Application.Resources>

Upvotes: 1

Related Questions