Search code examples
wpfxamlwindows-phone-7resourcedictionary

How do I cross reference MergedDictionaries in Windows Phone?


The WPF documentation on MergedDictionaries suggests that if you load two ResourceDictionaries in XAML, the second loaded one will be able to reference the first. The Windows Phone documentation on MergedDictionaries does not explicity state this but I assume the same rules apply. However the following does not work in my Windows Phone App.xaml,

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="View/ThemeDictionaries/LightThemeResourceDictionary.xaml"/>
    <ResourceDictionary Source="View/ThemeDictionaries/MainResourceDictionary.xaml"/>
</ResourceDictionary.MergedDictionaries>

The debug says the MainResourceDictionary line cannot reference SubTitleTextColor which is defined in LightThemeResourceDictionary - I have checked the spelling of the reference.

Is this type of loading not possible in Windows Phone? How do I work around it?


Solution

  • Based on the Silverlight Resources documentation (much more applicable than the WPF ones), this scenario won't work. There are 2 ways to get around this:

    • merge the first dictionary into the second one instead of the app's dictionary.
    • create an attached property that has a List<ResourceDictionary> that will manually merge them into one giant ResourceDictionary and set the application's resources to it.