I have a c# project that was a WPF application but I now want to build it as a dll. I have previously done this by removing the app.xaml from the project and setting its bui
You have to create separate ResourceDictionary file e.g. Style.xaml that contains (don't forget namespaces)
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Resources/Styles/Shared.xaml"/>
<ResourceDictionary Source="Resources/Styles/ToolBar.xaml"/>
<ResourceDictionary Source="Resources/Styles/GroupBox.xaml"/>
<ResourceDictionary Source="Resources/Styles/ZoomBox.xaml"/>
<ResourceDictionary Source="Resources/Styles/ScrollBar.xaml"/>
<ResourceDictionary Source="Resources/Styles/Expander.xaml"/>
<ResourceDictionary Source="Resources/ApplicationToolbar.xaml"/>
<ResourceDictionary Source="Resources/DesignerItem.xaml"/>
<ResourceDictionary Source="Resources/Styles/ToolboxItem.xaml"/>
<ResourceDictionary Source="Resources/Styles/Toolbox.xaml"/>
<ResourceDictionary Source="Resources/Connection.xaml"/>
<ResourceDictionary Source="Resources/Slider.xaml"/>
<ResourceDictionary Source="Resources/ScrollViewer.xaml"/>
<ResourceDictionary Source="Resources/StatusBar.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
end reference it in all of yours controls
This code works for me. I just changed the URIs to relative:
ResourceDictionary myResourceDictionary = new ResourceDictionary();
myResourceDictionary.Source = new Uri("Dictionary1.xaml", UriKind.Relative);
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
myResourceDictionary.Source = new Uri("Dictionary2.xaml", UriKind.Relative);
Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
I think you need to specified the name of the component were the resource is sitting in
<ResourceDictionary Source="/<YourDllName>;component/Resources/Styles/Shared.xaml" />
If your dll is named My.Wpf.Component.dll you should put My.Wpf.Component
so in code it should be
Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri(@"/<YourDllName>;component/Resources/Styles/Shared.xaml", UriKind.Relative) });