0

I have am creating a WPF extension to an existing Win32 MFC client application. Within a UserControl located in my WPF class library, I am merging libraries as follows:

 <ResourceDictionary.MergedDictionaries>                
                <ResourceDictionary Source="MyResourceDLL;Component/dictionaries/styles.xaml"/>
            </ResourceDictionary.MergedDictionaries>

I also tried

   <ResourceDictionary.MergedDictionaries>                
                    <ResourceDictionary Source="pack://application:,,,/MyResourceDLL;Component/dictionaries/styles.xaml"/>
                </ResourceDictionary.MergedDictionaries>

In either case, I get the following XamlParseException:

System.Windows.Markup.XamlParseException occurred
Message="MyResourceDLL;Component/dictionaries/styles.xaml' value cannot be assigned to property 'Source' of object 'System.Windows.ResourceDictionary'. Cannot locate resource 'ems.wpf.resources;component/dictionaries/styles.xaml'. Error at object 'System.Windows.ResourceDictionary' in markup file 'SARMaster.Maryln.EphemerisLib;component/getephemeriscontrol.xaml' Line 9 Position 37."

I there a way I can load a relative DLL that is not referenced by main project?

Rex Logan
  • 26,248
  • 10
  • 35
  • 48
Klaus Nji
  • 18,107
  • 29
  • 105
  • 185
  • Don't understand. Why not reference the assembly containing the resource dictionary? You need to explain your situation further, I think. – Kent Boogaart Jul 09 '11 at 08:25
  • Have you tried [this](http://stackoverflow.com/questions/709087/load-a-resourcedictionary-from-an-assembly)? – dowhilefor Jul 10 '11 at 02:51
  • Kent, the WPF class library is referencing the assembly that contains the resource dictionary. I need to tell the hosting MFC app to copy all the managed DLLs to its output directory or something. Adding this assembly reference to the MFC project does not copy it to its output directory, unlike a WPF host. If I manually copy files myself, all is well. – Klaus Nji Jul 10 '11 at 14:53
  • dowhilefor, the link u provided was helpful, thanks. I think this is mostly a problem of build path. If I get my assemblies into the MFC host's output directory, all is well and good. – Klaus Nji Jul 10 '11 at 15:04
  • ... or it could be that assembly being referenced in used only in XAML and not in code with no reference in the entry project, it is not being loaded by the runtime. – Klaus Nji Jul 10 '11 at 15:20

2 Answers2

0

I've been looking at the same issue recently. When compiling a Win32 CLR project the dependencies of the assemblies referenced by the MFC project aren't copied, so I simply set up a post-build event to copy the appropriate assemblies to the $(TargetDir).

Not ideal, but I believe it's by design.

JohnB
  • 117
  • 1
  • 5
0

I got the same problem and I found the solution. I needed to remove the Style of my ContentPresenter. This line was creating the XamlParseException:

<ContentPresenter.Resources>
    <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource TextStyle}"/>
</ContentPresenter.Resources>

And after fixing this error, I needed to do these steps to have something 100% working:

Here my projects:

  • StyleProject: the Class Library project that I want to use. It contains my styles
  • MainProject: the project that will use the styles

To do so:

  1. Add the reference of my StyleProject inside my MainProject (see here)
  2. Create a ResourceDictionary called MyStyle.xaml inside my MainProject
  3. Add the different dictionaries of my StyleProject following this answer to MyStyle.xaml
  4. Add MyStyle.xaml to the App.xaml using the following code

Code:

<ResourceDictionary Source="Resources/MyStyle.xaml"/>
Community
  • 1
  • 1
Morgane
  • 123
  • 2
  • 13