Application.Resources Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets a collection of application-scoped resources, such as styles, templates, and brushes.
Assembly: System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.
<Application> <Application.Resources> oneOrMoreResourceElements </Application.Resources> </Application>
XAML Values
Property Value
Type: System.Windows.ResourceDictionaryA ResourceDictionary object that contains zero or more application-scoped resources.
The value of the Resources property contains the ResourceDictionary that is set from XAML by using the Application.Resources property element.
The following example shows a style (textBlockStyle) declared as an application-scoped resource that is shared across multiple UIs.
First, the resource is implemented in the markup for the application class, as shown here.
<Application x:Class="WindowsPhoneApp1.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"> <!--Application Resources--> <Application.Resources> <Style x:Key="textBlockStyle" TargetType="TextBlock"> <Setter Property="Foreground" Value="Red" /> </Style> </Application.Resources> <Application.ApplicationLifetimeObjects> <!--Required object that handles lifetime events for the application--> <shell:PhoneApplicationService Launching="Application_Launching" Closing="Application_Closing" Activated="Application_Activated" Deactivated="Application_Deactivated"/> </Application.ApplicationLifetimeObjects> </Application>
The following UIs demonstrate the application-scoped textBlockStyle being shared.
<phone:PhoneApplicationPage xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" xmlns:local="clr-namespace:WindowsPhoneApp1" x:Class="WindowsPhoneApp1.Page" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="800" d:DesignWidth="480"> <StackPanel> <TextBlock Style="{StaticResource textBlockStyle}"> This text is red! </TextBlock> <local:AnotherPage /> </StackPanel> </phone:PhoneApplicationPage>
<phone:PhoneApplicationPage xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone" xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone" x:Class="WindowsPhoneApp1.AnotherPage" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="800" d:DesignWidth="480"> <StackPanel> <TextBlock Style="{StaticResource textBlockStyle}"> This text is red too! </TextBlock> </StackPanel> </phone:PhoneApplicationPage>