tags:

views:

186

answers:

2

I am using the Managed Extensibility Framework for a WPF application. I've defined interfaces for so-called extension points which provide new features to the application.

Some of these features might be to display data using certain data templates, which is something which you will probably want to specify in a xaml resources file.

If I have one of these extension points (ie plugins in plain language) defined in an assembly which is not known at application compile time, but I still want to merge the plugin's resources with those of the application how would I go about it?

All the examples that shows how to do this using the pack URI notation state that is the solution when the assemblies that you reference are known at compile time. How do you achieve the same thing when you aren't familiar with the assembly at compile-time?

+2  A: 

You need to get - either by code or convention - the details of the resource dictionary to be merged. The details could be the name of the resource dictionary or the ResourceDictionary instance itself.

In the latter case, you have the ResourceDictionary instance so you can just merge it into your Application-level (or whatever level is suitable) resources.

In the former case, you'll need to construct an appropriate pack URI using the name of the assembly (which you can get from the extension by calling extension.GetType().Assembly). Then create a ResourceDictionary whose Source is set to the pack URI. Finally, merge that into the appropriate level of your resource tree.

HTH, Kent

Kent Boogaart
Great answer. +1Another great answer given this specific set of constraints is in this post: http://stackoverflow.com/questions/842571/using-mef-to-import-a-wpf-datatemplate
Pieter Breed
A: 

Here's how to pull in resource dictionaries from parts into your application resources using MEF (in this case for data templates). I based SoapBox Core on this method of importing resource dictionaries for Views.

Scott Whitlock