0 out of 1 rated this helpful - Rate this topic

Application.Resources Property

Gets a collection of application-scoped resources, such as styles, templates, and brushes.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
public ResourceDictionary Resources { get; set; }
<Application>
  <Application.Resources>
    oneOrMoreResourceElements
  </Application.Resources>
</Application>

XAML Values

oneOrMoreResourceElements

One or more object elements, each of which creates and defines a resource. Each resource property element within each ResourceDictionary must have a unique value for the x:Key, which serves as the unique key when values are retrieved from the ResourceDictionary.

Property Value

Type: System.Windows.ResourceDictionary
A 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.

Run this sample

First, the resource is implemented in the markup for the application class, as shown here.


<Application 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    x:Class="SilverlightApplication.App"
    Startup="App_Startup">

    <Application.Resources>
        <Style x:Key="textBlockStyle" TargetType="TextBlock">
            <Setter Property="Foreground" Value="Red" />
        </Style>
    </Application.Resources>

</Application>


The following UIs demonstrate the application-scoped textBlockStyle being shared.


<UserControl 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SilverlightApplication"
    x:Class="SilverlightApplication.Page">

    <StackPanel>
        <TextBlock Style="{StaticResource textBlockStyle}">
            This text is red!
        </TextBlock>
        <local:AnotherPage />
    </StackPanel>

</UserControl>



<UserControl 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="SilverlightApplication.AnotherPage">

    <StackPanel>
        <TextBlock Style="{StaticResource textBlockStyle}">
            This text is red too!
        </TextBlock>
    </StackPanel>

</UserControl>


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ