Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ResourceDictionary Class

Provides a hashtable / dictionary implementation that contains WPF resources used by components and other elements of a WPF application.

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

<LocalizabilityAttribute(LocalizationCategory.Ignore)> _
Public Class ResourceDictionary
	Implements IDictionary, ICollection, IEnumerable, INameScope, _
	ISupportInitialize, IUriContext
Dim instance As ResourceDictionary

/** @attribute LocalizabilityAttribute(LocalizationCategory.Ignore) */ 
public class ResourceDictionary implements IDictionary, ICollection, 
	IEnumerable, INameScope, ISupportInitialize, IUriContext
public class ResourceDictionary implements IDictionary, ICollection, 
	IEnumerable, INameScope, ISupportInitialize, IUriContext
<ResourceDictionary .../>
 resourcesProperty  A property specifying a property element, where the value type of that property is ResourceDictionary. Typically, this is the Resources property of FrameworkElement or FrameworkContentElement, or of Application in an application resources case.  oneOrMoreResources  One or more resources specified as object elements. Each resource that you specify must have an x:Key Attribute assigned. 

The items in a ResourceDictionary are not immediately processed when application code is loaded by a XAML loader. Instead, the ResourceDictionary remains as an object and the individual values are processed only when they are specifically requested.

The ResourceDictionary class is not a DictionaryBase subclass. Instead, the ResourceDictionary class implements IDictionary but relies on a Hashtable internally.

In Extensible Application Markup Language (XAML), the ResourceDictionary class is typically an implicit collection element that is the object element value of several Resources properties, when given in property element syntax. For details on implicit collections in XAML, see XAML Syntax Terminology. An exception is when you want to specify a merged dictionary; for details, see Merged Resource Dictionaries.

This example shows how to use application resources.

The following example shows an application definition file. The application definition file defines a resource section (a value for the Resources property). Resources defined at the application level can be accessed by all other pages that are part of the application. In this case, the resource is a declared style. Because a complete style that includes a control template can be lengthy, this example omits the control template that is defined within the ContentTemplate property setter of the style.

  <Style TargetType="Button" x:Key="GelButton" >
    <Setter Property="Margin" Value="1,2,1,2"/>
    <Setter Property="HorizontalAlignment" Value="Left"/>
    <Setter Property="Template">



The following example shows a XAML page that references the application-level resource that the previous example defined. The resource is refenced by using a StaticResource Markup Extension that specifies the unique resource key for the requested resource. No resource with key of "GelButton" is found in the current page, so the resource lookup scope for the requested resource continues beyond the current page and into the defined application-level resources.

  <Button Height="50" Width="250" Style="{StaticResource GelButton}" Content="Button 1" />
  <Button Height="50" Width="250" Style="{StaticResource GelButton}" Content="Button 2" />

For the complete sample, including the complete control template, see Application Resources Sample.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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

© 2015 Microsoft