ResourceDictionary Class
Provides a hash table / dictionary implementation that contains WPF resources used by components and other elements of a WPF application.
System.Windows.ResourceDictionary
System.Activities.Core.Presentation.Themes.DesignerStylesDictionary
Namespace: System.Windows
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
[LocalizabilityAttribute(LocalizationCategory.Ignore)] [AmbientAttribute] [UsableDuringInitializationAttribute(true)] public class ResourceDictionary : IDictionary, ICollection, IEnumerable, ISupportInitialize, IUriContext, INameScope
<ResourceDictionary .../>
<object> <object.resourcesProperty> oneOrMoreResources </object.resourcesProperty> </object>
XAML Values
The ResourceDictionary type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Count | Gets the number of entries in the base ResourceDictionary. |
![]() | DeferrableContent | Infrastructure. Gets or sets the deferrable content for this resource dictionary. |
![]() | IsFixedSize | Gets whether this ResourceDictionary is fixed-size. |
![]() | IsReadOnly | Gets whether this ResourceDictionary is read-only. |
![]() | Item | Gets or sets the value associated with the given key. |
![]() | Keys | Gets a collection of all keys contained in this ResourceDictionary. |
![]() | MergedDictionaries | 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. |
| Name | Description | |
|---|---|---|
![]() | Add | Adds a resource by key to this ResourceDictionary. |
![]() | BeginInit | 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 | Determines whether the ResourceDictionary contains an element with the specified key. |
![]() | CopyTo | Copies the ResourceDictionary elements to a one-dimensional DictionaryEntry at the specified index. |
![]() | EndInit | Ends the initialization phase, and invalidates the previous tree such that all changes made to keys during the initialization phase can be accounted for. |
![]() | Equals(Object) | Determines whether the specified object is equal to the current object. (Inherited from Object.) |
![]() | Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) |
![]() | FindName | Not supported by this Dictionary implementation. |
![]() | GetEnumerator | Returns an IDictionaryEnumerator that can be used to iterate through the ResourceDictionary. |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | OnGettingValue | Occurs when the ResourceDictionary receives a request for a resource. |
![]() | RegisterName | Not supported by this Dictionary implementation. |
![]() | Remove | Removes the entry with the specified key from the base dictionary. |
![]() | ToString | Returns a string that represents the current object. (Inherited from Object.) |
![]() | UnregisterName | Not supported by this Dictionary implementation. |
| Name | Description | |
|---|---|---|
![]() | AsParallel | Enables parallelization of a query. (Defined by ParallelEnumerable.) |
![]() | AsQueryable | Converts an IEnumerable to an IQueryable. (Defined by Queryable.) |
![]() | Cast<TResult> | Casts the elements of an IEnumerable to the specified type. (Defined by Enumerable.) |
![]() | OfType<TResult> | Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.) |
| Name | Description | |
|---|---|---|
![]() ![]() | ICollection.CopyTo | Infrastructure. For a description of this member, see ICollection.CopyTo. |
![]() ![]() | ICollection.IsSynchronized | Infrastructure. For a description of this member, see ICollection.IsSynchronized. |
![]() ![]() | ICollection.SyncRoot | For a description of this member, see ICollection.SyncRoot. |
![]() ![]() | IEnumerable.GetEnumerator | Infrastructure. For a description of this member, see IEnumerable.GetEnumerator. |
![]() ![]() | IUriContext.BaseUri | For a description of this member, see IUriContext.BaseUri. |
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 x:Key value.
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.
<Application.Resources> <Style TargetType="Button" x:Key="GelButton" > <Setter Property="Margin" Value="1,2,1,2"/> <Setter Property="HorizontalAlignment" Value="Left"/> <Setter Property="Template"> <Setter.Value> ... </Setter.Value> </Setter> </Style> </Application.Resources>
The following example shows a XAML page that references the application-level resource that the previous example defined. The resource is referenced 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.
<StackPanel Name="root" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" > <Button Height="50" Width="250" Style="{StaticResource GelButton}" Content="Button 1" /> <Button Height="50" Width="250" Style="{StaticResource GelButton}" Content="Button 2" /> </StackPanel>
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.






