I have a Windows Forms application that needs to host a WPF control at runtime. I have the basic hosting and interaction complete (using an ElementHost control) and everything works fine until I try to do something that requires the WPF control to make use of some custom resource dictionaries that are defined. (The WPF control and all of it's resource dictionaries are all defined in the same WPF Control Library DLL.)
As soon as that happens, I get a bunch of errors that look like this:
System.Windows.ResourceDictionary Warning: 9 : Resource not found; ResourceKey='DocumentHeaderInterestStyle'
I have found one reference that talks about this, but it seems like the article is approaching things more from the WPF side, but I don't really want to have to make changes to the WPF control as everything works in a stand-alone WPF application.
If the only way to accomplish this is to make changes on the WPF side, I can get those changes made (I'm not responsible for the WPF control library but the person that is also works for the same company so it's not a problem other than getting his time to make the changes.) but I'm hoping for something I can do on the WinForms side to get this working.
The WPF control library has a resource dictionary file named "Default.xaml" defined in the project with the following properties:
Build Action: Page Copy to Output Directory: Do not copy Custom Tool: MSBuild:Compile
The stand-alone WPF application has the following entry in it's App.xaml file:
<ResourceDictionary x:Uid="ResourceDictionary_1">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary x:Uid="ResourceDictionary_2" Source="/SmartClient.Infrastructure;component/Themes\Default.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
It seems like the control library should already know how to get its resources. Using the Resources.MergedDictionaries.Add() seems like it should work, but where do I get the instance of the existing dictionary?