--- title: "How to: Use an Application-Scope Resource Dictionary" description: Learn how to define and use an application-scope custom resource dictionary in Windows Presentation Foundation (WPF). ms.date: "03/30/2017" dev_langs: - "csharp" - "vb" helpviewer_keywords: - "dictionaries [WPF], resource" - "resource dictionaries [WPF], application-scope" - "application-scope resource dictionaries" ms.assetid: 53857682-bd2c-4f2c-8f25-1307d0b451a2 --- # How to: Use an Application-Scope Resource Dictionary This example shows how to define and use an application-scope custom resource dictionary. ## Example exposes an application-scope store for shared resources: . By default, the property is initialized with an instance of the type. You use this instance when you get and set application-scope properties using . For more information, see [How to: Get and Set an Application-Scope Resource](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/aa348547(v=vs.100)). If you have multiple resources that you set using , you can instead use a custom resource dictionary to store those resources and set with it instead. The following shows how you declare a custom resource dictionary using XAML. [!code-xaml[HOWTOResourceDictionaries#1](~/samples/snippets/csharp/VS_Snippets_Wpf/HowToResourceDictionaries/CSharp/MyResourceDictionary.xaml#1)] Swapping entire resource dictionaries using allows you to support application-scope themes, where each theme is encapsulated by a single resource dictionary. The following example shows how to set the . [!code-xaml[HOWTOResourceDictionaries#2](~/samples/snippets/csharp/VS_Snippets_Wpf/HowToResourceDictionaries/CSharp/App.xaml#2)] The following shows how you can get application-scope resources from the resource dictionary exposed by in XAML. [!code-xaml[HOWTOResourceDictionaries#4](~/samples/snippets/csharp/VS_Snippets_Wpf/HowToResourceDictionaries/CSharp/MainWindow.xaml#4)] The following shows how you can also get the resources in code. [!code-csharp[HOWTOResourceDictionaries#3](~/samples/snippets/csharp/VS_Snippets_Wpf/HowToResourceDictionaries/CSharp/MainWindow.xaml.cs#3)] [!code-vb[HOWTOResourceDictionaries#3](~/samples/snippets/visualbasic/VS_Snippets_Wpf/HowToResourceDictionaries/VB/MainWindow.xaml.vb#3)] There are two considerations to make when using . First, the dictionary *key* is an object, so you must use exactly the same object instance when both setting and getting a property value. (Note that the key is case-sensitive when using a string.) Second, the dictionary *value* is an object, so you will have to convert the value to the desired type when getting a property value. ## See also - - - [XAML Resources](/dotnet/desktop-wpf/fundamentals/xaml-resources-define) - [Merged Resource Dictionaries](../advanced/merged-resource-dictionaries.md)