0

I am working with Prism modules. That means I have a lot of projects inside my solution and I would like to share my WPF styles across all of them.

Currently I am simply adding them to all my xaml files. As Example:

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Pack://application:,,,/MyProject.Shared;component/Styles/Colors.xaml" />
        </ResourceDictionary.MergedDictionaries>
    <ResourceDictionary>
<UserControl.Resources>

I was wondering if there is a better solution for this problem.

Edit: The "possible duplicate" is actually what I am doing at the moment. I want to get rid of this repetitive code snippet in each of my UserControls. Since most of my projects are UserControlLibraries / Prism Modules they don´t have a kind of App.xaml where I can define the ResourceDictionaries.

TomTomB
  • 419
  • 1
  • 4
  • 13
  • Possible duplicate of [How to organize resources (styles, ...) in a complex WPF scenario?](https://stackoverflow.com/questions/15249492/how-to-organize-resources-styles-in-a-complex-wpf-scenario) – Amittai Shapira Dec 21 '17 at 16:04
  • Defining the common resources in a shared assembly is a good solution. You may want to merge the common resource dictionaries into the App.xaml of the running application instead of doing it in each individual UserControl. – mm8 Dec 21 '17 at 16:05

1 Answers1

0

A default WPF project should have a App.xaml file. Assuming your project still has that, you can add your Resource Dictionaries there under the Application.Resources tag.

see: https://learn.microsoft.com/en-us/dotnet/framework/wpf/app-development/how-to-use-an-application-scope-resource-dictionary

Jan Paolo Go
  • 5,842
  • 4
  • 22
  • 50