Question

I have a problem when loading an external plugin that makes use of a resource dictionary. I am using MEF and lazy loading for loading a user control in an external assembly, which is a User control library project.

This user control references a resource dictionary in the following way, and it is marked as en export:

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source ="MyTheme.xaml" />   
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

The main application loads the plugin, and imports its resource dictionaries like this:

[ImportMany(typeof(ResourceDictionary))]
private IEnumerable<ResourceDictionary> _resourceDictionaries { get; set; }

private void Load()
{
   foreach (var resourceDictionary in _resourceDictionaries)
   {
        Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
   }
}

This works and loads the user control and the dictionary from the external assembly. However, when creating the instance of the control, the main app throws an exception stating it can not find the referenced ResourceDictionary.

How can I make my host app aware of where to look for its external user control resource dictionary? Or should I change the way my user control is referencing its resources?

Was it helpful?

Solution

Ok got it working. The resource file had to be set as Resource in the build action.

More details here: Loading merged ResourceDictionary from different assembly fails

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