Having resources in a shared library (the sample has the library named WpfStylesLib), shared resources (Dictionary1.xaml), with a WPF application the resources can be made available application-wide by adding the resource dictionary to the MergedDictionaries in the file App.xaml. To reference the shared library I’m using the relative Pack URI syntax. Following the / is the name of the assembly: WpfStylesLib. ;component following the assembly name means the assembly is referenced from the local assembly. Dictionary1.xaml is the resource name in the referenced assembly. Now all the resources defined within this dictionary can be used from the WPF application.
<Application x:Class="WPFResourceTest.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="/WpfStylesLib;component/Dictionary1.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
...
...
WPF.Application app = new WPF.Application();WPF.ResourceDictionary dict = new WPF.ResourceDictionary();
dict.Source =
new Uri("pack://application:,,,/StylesLib;component/Dictionary1.xaml");
WPF.Application.Current.Resources.MergedDictionaries.Add(dict);
Read more: Christian Nagel's Blog