Silverlight: several projects sharing style files

I have several silverlight projects in which I would like to use the same styles, color scheme and some template objects.

How to do it?

+6
silverlight
source share
2 answers

One way to do this is to create a new silverlight class library that will be your common theme / build style that other silverlight projects will reference. This assembly will contain one or more Dictionary XAML files, which can define all your styles, brushes, and patterns. You could even create several cascading hierarchy styles using the BasedOn attribute of the Style class.

You can then use MergedDictionaries to combine these styles into your application, either at the App.xaml or page level.

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

Then you would refer to common styles / brushes, as usual, to any other StaticResource.

+11
source share

There are two options: first, like Dan, you can create a library that is shared by other projects. If clients access several of your projects, and your projects use application library caching, you reduce the overall download size.

Another approach is to create a resource dictionary in one project, and then add the same file to other projects. Notice that in the Add Existing Item dialog box, the Add button has a small drop-down image, a drop-down menu, and then select Add As Link.

This makes dicitionary a plain Xaml file. One of the advantages that I see in this is to actually leave the dictionary file from Xap and just put it in the clientBin folder (or any other folder that Xap is placed in). This approach allows all Xaps to use a single dictionary (just like the first approach does), but allows you to modify Xaml without useless rebuilds.

+4
source share

All Articles