Search code examples
wpfxamlresourcedictionary

How do I make some wpf resources (e.g. styles, brushes etc.) that are visible to all resource dictionaries?


I am new to WPF and using resource dictionaries. I want to create some styles that are accessible to all resource dictionaries but I don't know what is the appropriate way to do that? I also want to know how to use resources in another resource dictionary in a resource dictionary.


Solution

  • You can do this by using Application.Resources in App.xaml. Create a Resource Dictionary where you want to store and just put your your Resource Dictionary name in the source of ResourceDictionary.

      <Application.Resources>
                <ResourceDictionary>
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary Source="Your Resource Dictionary Name"/>
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
            </Application.Resources>