Use a ResourceDictionay and an external resources located in an assembly

I have notice that some developers are asking questions about how to use a ResourceDictionary and reference it to a resource located in a separate assembly. Here is a simple step by step guide to make it possible, I assume you already have a Silverlight project created:

1) Create a new Silverlight Class Library

image


2) Add a Silverlight Resource Dictionary file to the Class Library project

image


3) Add your styles to it and build


image

4) From your Silverlight Application, add a reference to the Silverlight Class Library Project or assembly file

image

5) In the Resource property of the App, or UserContorl etc add a ResourceDictionary element, set the source property by using the following pattern ”/<assembly>;component/<resource>.xaml”. If the name of your Silverligth Class Library is ”MyClassLib” and have a Resource Dictionary file called MyDictionary.xaml in the root folder of the Silverlight Class Library, the Source property should have the following value:

<ResourceDictionary Source=”/MyClassLib;component/MyDictionary.xaml”/>


image

6) You can now use the styles.


If you don’t have more than just a Dictionary Resources added to the Assembly, and want to share the resources to other Silverlight app, just use a simple .xaml file which you copy and share among the different Silverlight apps, easier to add and use, and you can avoid extra dependencies to an assembly and adding references. Only use an assembly with a resource if you want to protect the resource so others can’t change your original resource, or have controls or other logic added into your assembly which you are going to use in your Silverlight app.

Published Wednesday, September 16, 2009 2:09 PM by Fredrik N
Filed under:

Comments

# Use a ResourceDictionay and an external resources located in an assembly - Fredrik Normén

Friday, September 18, 2009 9:57 AM by DotNetShoutout

Thank you for submitting this cool story - Trackback from DotNetShoutout

# re: Use a ResourceDictionay and an external resources located in an assembly

Friday, September 18, 2009 11:20 AM by Chris Maduro

This is not working for me. I want to put it in the App.xaml file. I'm also using Prism, which should not really be an issue here. I get a value is out of range on the source string.

# Tune Up Your PC &raquo; Post Topic &raquo; Silverlight Postings

Saturday, September 19, 2009 11:40 AM by Tune Up Your PC » Post Topic » Silverlight Postings

Pingback from  Tune Up Your PC  &raquo; Post Topic   &raquo; Silverlight Postings

# Silverlight Postings | Codedstyle

Saturday, September 19, 2009 1:28 PM by Silverlight Postings | Codedstyle

Pingback from  Silverlight Postings | Codedstyle

# Silverlight Postings &laquo; Jasper Blog

Monday, September 21, 2009 3:08 AM by Silverlight Postings « Jasper Blog

Pingback from  Silverlight Postings &laquo; Jasper Blog

# Using ResourceDictionary in Silverlight &laquo; Amir Aryani

Tuesday, February 16, 2010 12:39 AM by Using ResourceDictionary in Silverlight « Amir Aryani

Pingback from  Using ResourceDictionary in Silverlight &laquo; Amir Aryani

Leave a Comment

(required) 
(required) 
(optional)
(required)