Resource​Dictionary Class

Definition

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

[System.Windows.Localizability(System.Windows.LocalizationCategory.Ignore)]
[System.Windows.Markup.Ambient]
[System.Windows.Markup.UsableDuringInitialization(true)]
public class ResourceDictionary : System.Collections.IDictionary, System.ComponentModel.ISupportInitialize, System.Windows.Markup.INameScope, System.Windows.Markup.IUriContext
Inheritance
ResourceDictionary
Derived
Attributes
Implements

Inherited Members

System.Object

Remarks

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

The ResourceDictionary class is not derived from DictionaryBase. 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 In Detail. An exception is when you want to specify a merged dictionary; for details, see Merged Resource Dictionaries.

Another possible XAML usage is to declare a resource dictionary as a discrete XAML file, and either load it at run time with Load or include it in a (full-trust) project as a resource or loose file. In this case, ResourceDictionary can be declared as an object element, serving as the root element of the XAML. You must map the appropriate XML namespace values (default for the WPF namespace and typically x: for the XAML namespace) onto the ResourceDictionary element if you plan to use it as the root element. Then you can add child elements that define the resources, each with an value.

XAML Implicit Collection Usage

<object>  
  <object.resourcesProperty>  
    oneOrMoreResources  
  </object.resourcesProperty>  
</object>  

XAML Values

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 Directive assigned.

Constructors

Resource​Dictionary()

Initializes a new instance of the ResourceDictionary class.

Properties

Count

Gets the number of entries in the base ResourceDictionary.

Deferrable​Content

Gets or sets the deferrable content for this resource dictionary.

Is​Fixed​Size

Gets whether this ResourceDictionary is fixed-size.

Is​Read​Only

Gets whether this ResourceDictionary is read-only.

Item(​Object)

Gets or sets the value associated with the given key.

Keys

Gets a collection of all keys contained in this ResourceDictionary.

Merged​Dictionaries

Gets a collection of the ResourceDictionary dictionaries that constitute the various resource dictionaries in the merged dictionaries.

Source

Gets or sets the uniform resource identifier (URI) to load resources from.

Values

Gets a collection of all values associated with keys contained in this ResourceDictionary.

Methods

Add(​Object, ​Object)

Adds a resource by key to this ResourceDictionary.

Begin​Init()

Begins the initialization phase for this ResourceDictionary.

Clear()

Clears all keys (and values) in the base ResourceDictionary. This does not clear any merged dictionary items.

Contains(​Object)

Determines whether the ResourceDictionary contains an element with the specified key.

Copy​To(​Dictionary​Entry[], ​Int32)

Copies the ResourceDictionary elements to a one-dimensional DictionaryEntry at the specified index.

End​Init()

Ends the initialization phase, and invalidates the previous tree such that all changes made to keys during the initialization phase can be accounted for.

Find​Name(​String)

Not supported by this Dictionary implementation.

Get​Enumerator()

Returns an IDictionaryEnumerator that can be used to iterate through the ResourceDictionary.

On​Getting​Value(​Object, ​Object, ​Boolean)

Occurs when the ResourceDictionary receives a request for a resource.

Register​Name(​String, ​Object)

Not supported by this Dictionary implementation.

Remove(​Object)

Removes the entry with the specified key from the base dictionary.

Unregister​Name(​String)

Not supported by this Dictionary implementation.

Explicit Interface Implementations

I​Collection.​Copy​To(​Array, ​Int32)

For a description of this member, see CopyTo(Array, Int32).

I​Collection.​Is​Synchronized

For a description of this member, see IsSynchronized.

I​Collection.​Sync​Root

For a description of this member, see SyncRoot.

I​Enumerable.​Get​Enumerator()

For a description of this member, see GetEnumerator().

I​Uri​Context.​Base​Uri

For a description of this member, see BaseUri.

Extension Methods

Cast<TResult>(IEnumerable)

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

OfType<TResult>(IEnumerable)

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

AsParallel(IEnumerable)

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

AsQueryable(IEnumerable)

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