How to reference a resource dictionary defined in another assembly RRS feed

  • Question

  • Hi,

    I'm creating a Metro Style App in Xaml and C# that will have multiple themes. I would like to create a separate project with all the supported themes, with a resource dictionary file for each theme.

    The problem is I don't know how to reference a theme from main application.
    This is my App.xaml:

                    <ResourceDictionary Source="ms-resource://MyApplication.Themes/Files/DefaultTheme.xaml"/>
                <vm:ViewModelLocator x:Key="ViewModelLocator" />

    DefaultTheme.xaml is defined in MyApplication.Themes assembly and its Build Action is set to Embedded Resource.
    At design time I have the following error: An error occured while finding the resource dictionary "ms-resource://MyApplication.Themes/Files/DefaultTheme.xaml".

    Sunday, March 18, 2012 12:21 PM


  • You have to use ms-appx for Resource dictionaries in dlls. The Build Action should be Page.


    If you have a dll named "CustomControl" with a ResourceDictionary named "Styles.xaml", the App.xaml should contain

                    <ResourceDictionary Source="ms-appx:///CustomControls/Styles.xaml"/>

    Hope this helps.

    -Navit Saxena 

    Sunday, March 18, 2012 10:26 PM