Dan Freve
Dan Freve

Reputation: 21

How can I merge a resource dictionary located in an assembly in a different folder?

I have a solution with the following folder structure:

Solution 
  MainApplication
    MainWindow.xaml
  SharedResourcesLibrary (Class library project)
    GlobalResources.xaml
  SubFolder
    ControlLibrary (Class library project)
      MyUserControl.xaml

I need to merge the GlobalResources.xaml dictionary into the resources for MainWindow.xaml and MyUserControl.xaml.

I have successfully merged GlobalResources.xaml into MainWindow.xaml using the following syntax in MainWindow.xaml:

<ResourceDictionary Source="/SharedResourcesLibrary;component/GlobalResources.xaml" />

However, I cannot figure out how to merge GlobalResource.xaml into the resources for MyUserControl.xaml. I have tried the Pack URI syntax as follows:

<ResourceDictionary.MergedDictionaries>
  <ResourceDictionary Source="pack://application:,,,/SharedResourcesLibrary;component/GlobalResources.xaml" />
</ResourceDictionary.MergedDictionaries>

...but this does not seem to work properly. I get the following error message in the Visual Studio 2012 xaml editor:

An error occurred while finding the resource dictionary "pack://application:,,,/SharedResourcesLibrary;component/GlobalResources.xaml"

What is the correct way to merge this dictionary into MyUserControl properly?

Upvotes: 1

Views: 1445

Answers (1)

Dan Freve
Dan Freve

Reputation: 21

It seems that this is only an issue in Visual Studio 2012. I opened my solution in Visual Studio 2010 and the designer works perfectly with the pack URI notation.

Upvotes: 1

Related Questions