Export (0) Print
Expand All

Application.Resources Property

Gets or sets a collection of application-scope resources, such as styles and brushes.

Namespace: System.Windows
Assembly: PresentationFramework (in presentationframework.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public ResourceDictionary Resources { get; set; }
/** @property */
public ResourceDictionary get_Resources ()

/** @property */
public void set_Resources (ResourceDictionary value)

public function get Resources () : ResourceDictionary

public function set Resources (value : ResourceDictionary)

<object>
  <object.Resources>
    <ResourceDictionary .../>
  </object.Resources>
</object>

Property Value

A ResourceDictionary object that contains zero or more application-scope resources.

The Resources property can be used to share resources across the windows and elements of an application. Additionally, the Resources property is included in the resource lookup path, which is traversed in the following order:

  1. Elements

  2. Windows

  3. Application.Resources

  4. System

Consequently, user interface (UI) elements can bind to application-scope resources. Additionally, if resources change, the resource system ensures that element properties which are bound to those resources are automatically updated to reflect the change.

Application-scope resources provide a simple way to support a consistent theme across your application. You can easily create a theme in XAML by using the Application.Resources tag. However, if your application supports multiple themes, which may contain a large number of theme elements, it might be easier to manage them using one ResourceDictionary instance for each theme. In this way, a new theme can be applied by setting the Resources property to the appropriate ResourceDictionary. For more information, including an example, see the Themed Application Sample.

Resources is thread-safe, and is available from any thread.

This example illustrates how to use XAML together with application-scope resources to create a consistent visual appearance.

<Application
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    StartupUri="MainWindow.xaml"
    >

  <Application.Resources>
    <SolidColorBrush x:Key="BackgroundColor" Color="Yellow"></SolidColorBrush>
  </Application.Resources>

</Application>

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ApplicationResourcesSnippetSample_XAML" 
    Height="300" 
    Width="300" 
    Background="{StaticResource BackgroundColor}"
    >
  <Grid>

	...

  </Grid>
</Window>

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft