When building large Silverlight applications, it makes sense to build sets of styles that can be shared across the application. Many examples on the web illustrate placing these in the
App.xaml file and then you are off to the races. Unfortunately, when you are building modular applications, it’s not that simple.
The first step is to take your theme for the application and place it in a separate project. These are themes that only have dependencies on the core Silverlight controls. What you want is a simple project that any application or module can reference to pull in the theme.
Create a new Silverlight class library, then add a
ResourceDictionary to house your themes. In larger projects, it makes sense to break out themes into smaller pieces, like this:
Then, you can aggregate these into your main dictionary, called
Theme.xaml or something similar. It is important that you load the child dictionaries in order. For example, building blocks like colors and gradients will come before more complicated control templates that use the colors and gradients. Your
Theme.xaml might look like this:
<pre><ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <ResourceDictionary.MergedDictionaries> <ResourceDictionary Source="ColorStyles.xaml" /> <ResourceDictionary Source="BrushStyles.xaml" /> <ResourceDictionary Source="TextStyles.xaml" /> <ResourceDictionary Source="ButtonStyles.xaml" /> <ResourceDictionary Source="ComboBoxStyles.xaml" /> </ResourceDictionary.MergedDictionaries> </ResourceDictionary></pre>