locked
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:

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

    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

Answers

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

    Example:

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

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

    Hope this helps.

    -Navit Saxena 

    Sunday, March 18, 2012 10:26 PM