Coming from the WPF world, finding out that Silverlight lacked the feature of distributing application resources among separate files was one of those kick in a head moments. Well, not anymore. Silverlight 3, like its big brother WPF, now supports partitioning resources through merged dictionaries.
Merged resource dictionaries can be included as external files (build action = Content), as included resources (build action = Resource), or as referenced assembly resources (e.g. theming).
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Themes/Theme1.xaml" />
<ResourceDictionary Source="Themes/Theme2.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Merged resource dictionaries come in useful when:
- providing different themes for the application (like in the sample below)
- providing a new style/template for existing control
- providing a style/template for a custom control
Run the sample online
Source code below:
9ad539b8-041c-4603-a30b-c9b0f45aedfa|1|1.0|27604f05-86ad-47ef-9e05-950bb762570c
Tags :