Application.Resources Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets a collection of application-scoped resources, such as styles, templates, and brushes.
ResourceDictionary Resources();
void Resources(ResourceDictionary value);
public ResourceDictionary Resources { get; set; }
var resourceDictionary = application.resources;
application.resources = resourceDictionary;
Public Property Resources As ResourceDictionary
Property Value
A ResourceDictionary object that contains zero or more application-scoped resources.
Examples
This example shows how to declare an app-specific resource (this one creates a common converter class instance). Then it adds an Application.MergedDictionaries property element with ResourceDictionary elements within, each referencing a XAML file by URI as the Source.
<Application.Resources>
<ResourceDictionary>
<common:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="rd1.xaml" />
<ResourceDictionary Source="rd2.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Remarks
The resource dictionary model in the Windows Runtime supports many of the XAML resource concepts you may be familiar with if you have created applications using Windows Presentation Foundation (WPF) or .NET MAUI. For more info, see ResourceDictionary and XAML resource references.
The resources you define in the ResourceDictionary that fills the Application.Resources
property element are available for retrieval from any page of your app. This is advantageous if many of your app's pages are all using the same resource. For example, if you have a SolidColorBrush resource that you're using for color schemes in your app's UI, and that color is used on most of your pages, it makes sense to declare that SolidColorBrush in the Application.Resources
.
When you add resources to Application.Resources
, add them either before or after any existing ResourceDictionary.MergedResources
. The rules of XAML don't allow you to put content on both sides of a property element tag. For more info, see XAML syntax guide.
Tip
If you use a resource on many pages throughout your app, then storing it in App.xaml is a good practice, and avoids duplication. But App.xaml is parsed at app startup so any resource that is used in only one page (unless that page is the initial page) should be put into the page's local resources. For more info, see Optimize your XAML markup.