Search code examples
c#wpfembedded-resource

Shared app.xaml between multiple solutions


I'm about to create multiple projects with WPF. I'm using styles to modify the look and feel of the applications and put them to the app.xaml.

But now i have the problem that i need to have the same styles in every project. Because copy and paste of the app.xaml content to every project is a very bad idea I'm looking for a solution to centralize the app.xaml to access the styles from every project.


Solution

  • You might create a common styles file in one of your project. For example, this might be a GenericStyles.xml file containing your styles and resources.

    In other projects, you could add this file as link: right click on a project -> Add -> Existing Item... -> select GenericStyles.xml file -> open the drop-down menu on the Add button -> select Add As Link.

    So now you have a single file that will be part of all your projects.

    In each project's app.xaml, you could add your styles and resources using this markup:

    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="GenericStyles.xml"/>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
    

    Now, you would have to change only one file in the "main" project, and the other projects would automatically apply these changes.