We help IT Professionals succeed at work.

How do I resolve a "Cannot locate resource" exception thrown when loading a WPF user control from a WPF Class Library?

jxbma
jxbma asked
on
Hi:

I'm a newbie at the world of WPF.

As a starting point/exercise, I've taken an existing WPF app (with subsequent customized controls) and
converted it to a class library. The library (dll) build without an warning/error messages.

I've trying to embed a control from the class library inside a window/control in my .Net winforms application.
I'm using the ElementHost control . The goal is to host the WPF control within the ElementHost control.
This piece compiles and looks fine.

However when I run my application,  I get the following exception:
=========================================
"'Set property 'System.Windows.ResourceDictionary.Source' threw an exception.' Line number '15' and line position '18'."      string
Systeim.IO.IOException -->  "Cannot locate resource 'dictionaries/brushes.xaml'."      string

The Class Library contains a couple of xaml resources that are shared amongst the WPF controls.
They are part of the Class Library's VS solution/project. I'm assuming that they get built into
the Class Library/DLL, otherwise my Class Library would not build.


I noticed that the "Exe" version had an "App.xaml" file which had the following section defined:
===========================================================
<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
              <ResourceDictionary Source="ResourceDictionaries/Brushes.xaml" />
               . . .

       </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>


What am I missing here?
Does the Class Library contain some sort of similar definition/construct?

Any help would be greatly appreciated, as I'm trying to throw together a quick demo and have already been working on this issue for several hours.

Thanks in advance,

JohnB
Comment
Watch Question

jxbmaSoftware Consultant

Author

Commented:
Ultimately, after some refactoring, this solution worked.

Thanks for the advise!
JB