0

Resource dictionary

03-11-2010 10:56 AM |

I have two different projects. I linked a resource directory in using add existing item add as link.

Silverlight does not see the resource dictionary when it is a linked file and give me an out of range error.

Any work around to this or any better way to use the same file across two projects?

Xander
  • 9,069
  • 14
  • 70
  • 129

2 Answers2

0

If the share is between a silverlight and a WPF project, I find it easier to put the file inside the silverlight project, and link it to the WPF project, than doing it the other way around.

In other words the file is moved to the silverlight project, not the WPF project, then "linked" to the WPF project.

Also remember when the file is referenced from WPF, since it is linked, you need to change the reference URL as if it is in the root, like so:

<ResourceDictionary 
    Source="pack://application:,,,/AssemblyName;component/DictionaryName.xaml" />

Removing the folder above works, the uri below does NOT work:

<ResourceDictionary 
    Source="pack://application:,,,/AssemblyName;component/FOLDER/DictionaryName.xaml" />
Martin Lottering
  • 1,624
  • 19
  • 31
0

I would reference the assembly that has the resource dictionary normally (don't add it in as a link), and then bring it into the application using Merged Dictionaries. You can specify a resource dictionary in an external assembly to merge into the current application or page's resource dictionaries.

<Application.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/SharedThemeAssembly;component/MyStyles.xaml"/>
            ...other ResourceDictionaries to merge in...
        </ResourceDictionary.MergedDictionaries>
     </ResourceDictionary>
</Application.Resources>

I answered a similar SO question here: Silverlight: Multiple project sharing the same style files

Community
  • 1
  • 1
Dan Auclair
  • 3,607
  • 25
  • 32