Sharing xaml resource files across projects

Topics: CAB & Smart Client Software Factory
Jul 12, 2007 at 5:26 PM
This may be the incorrect forum for this question so I apologize in advance. I've created a common xaml resource dictionary that I want to share across multiple projects/modules. In Blend, I choose 'Link to existing item...' and pick my file which resides in a common, higher-level directory. Here are the specifics:

<Page Include="..\Client.App\Resources\AppStyles.xaml">

<ResourceDictionary Source="AppStyles.xaml"/>

Runtime Error
'AppStyles.xaml' value cannot be assigned to property 'Source' of object 'System.Windows.ResourceDictionary'. Cannot locate resource 'views/statusbarview/appstyles.xaml'. Error at object 'System.Windows.ResourceDictionary' in markup file 'Client.App.CoreUI.StatusBar;component/views/statusbarview/statusbarview.xaml' Line 9 Position 25.

Any ideas?

Jul 16, 2007 at 7:48 PM
Hi Michael, below is an extract of the Merged Resource Dictionaries’s help. Hope this helps you.

Merged Resource Dictionary URIs
There are several techniques for how to include a merged resource dictionary, which are indicated by the uniform resource identifier (URI) format that you will use. Broadly speaking, these techniques can be divided into two categories: resources that are compiled as part of the project, and resources that are not compiled as part of the project.
For resources that are compiled as part of the project, you can use a relative path that refers to the resource location. The relative path is evaluated during compilation. Your resource must be defined as part of the project as a Resource build action. If you include a resource .xaml file in the project as Resource, you do not need to copy the resource file to the output directory, the resource is already included within the compiled application. You can also use Content build action, but you must then copy the files to the output directory and also deploy the resource files in the same path relationship to the executable.
A related technique is to use a Pack URI to a XAML file, and refer to it as Source. Pack URI enables references to components of referenced assemblies and other techniques. For more information on Pack URIs, see Windows Presentation Foundation Application Data Files.
For resources that are not compiled as part of the project, the URI is evaluated at run time. You can use a common URI transport such as file: or http: to refer to the resource file. The disadvantage of using the noncompiled resource approach is that file: access requires additional deployment steps, and http: access implies the Internet security zone.

Ezequiel Jadib