You can add the resource dictionary in the same assembly as the module or in other loaded assembly, then access it programmatically by using the Application.GetResourceStream
method; however you will need to know the name of the assembly where the resource is defined.
For example, if your assembly is named TheAssembly
and the resource dictionary is named TheDictionary.xaml
, you can do (Disposes not shown for brevity):
StreamResourceInfo sr = Application.GetResourceStream(
new Uri("/TheAssembly;component/TheDictionary.xaml", UriKind.Relative));
StreamReader r=new StreamReader(sr.Stream);
string xaml=r.ReadToEnd();
ResourceDictionary rd = (ResourceDictionary)XamlReader.Load(xaml);
From here, you can for example use the Unity container to make the resource dictionary available application-wide.
UPDATE
The following version avoids having to hard-code the assembly name, provided that the resource is in the currently executing assembly:
string assemblyName = Assembly.GetExecutingAssembly().FullName.Split(',')[0];
string uri = string.Format("/{0};component/Dictionary1.xaml", assemblyName);
StreamResourceInfo sr = Application.GetResourceStream(
new Uri(uri, UriKind.Relative));
//etc...