Search code examples
windows-phone-7xamlresourcedictionarydatatemplatemergeddictionaries

I get a XamlParseException when i try to load a merged ResourceDictionary filled with DataTemplates


In my Windows Phone 7.5 application i want to have a merged ResourceDictionary filled with DataTemplates. To achieve this, i created a file called "DataTemplates.xaml" and filled it with DataTemplates like this:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <DataTemplate x:Key="ItemTemplate">
         <!-- xaml -->
    </DataTemplate>

    <DataTemplate x:Key="GroupHeaderTemplate">
        <!-- xaml -->
    </DataTemplate>

    <DataTemplate x:Key="GroupItemTemplate" >
         <!-- xaml -->
    </DataTemplate>
</ResourceDictionary>

In page where i want to use that DataTemplates i wrote this code:

    <phone:PhoneApplicationPage.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="/myAssemblyName;component/Resources/DataTemplates.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </phone:PhoneApplicationPage.Resources>

But, when i debug and try to navigate to the page that contains the ResourceDictionary i got a XamlParseException: Failed to assign to property 'System.Windows.ResourceDictionary.Source'

How can i do? :( Thank you!


Solution

  • Ok, i spent about 20 minutes to write question and after rereading it i found solution, so i answer myself: i accidentally wrote the namespace of solution instead of its assembly name! That's all, now the ResourceDictionary loads properly :)