Load a ResourceDictionary from an assembly

Christian Hubmann picture Christian Hubmann · Apr 2, 2009 · Viewed 25k times · Source

I've got an assembly somewhere on the file system, e.g. "C:\temp\test.dll". In that assembly there's a ResourceDictionary, e.g. "abc.xaml".

How can i get that ResourceDictionary? Maybe there is a way using Reflections? I didn't find a solution so far.

Thanks in advance!

Edit: Just wanted to add that I want to access the Resources in the Dictionary, e.g. a Style.

Answer

Claraoscura picture Claraoscura · May 28, 2009

You actually need to write the Uri like this:

Assembly.LoadFrom(@"C:\temp\test.dll");
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(@"pack://application:,,,/test;component/myresource.xaml");