ComponentResourceKey Class

Defines or references resource keys based on class names in external assemblies, as well as an additional identifier.

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

[TypeConverterAttribute(typeof(ComponentResourceKeyConverter))]
public class ComponentResourceKey : ResourceKey
See Remarks

The ComponentResourceKey type exposes the following members.

  NameDescription
Public methodComponentResourceKey()Initializes a new instance of the ComponentResourceKey class.
Public methodComponentResourceKey(Type, Object)Initializes a new instance of a ComponentResourceKey , specifying the Type that defines the key, and an object to use as an additional resource identifier.
Top

  NameDescription
Public propertyAssemblyGets the assembly object that indicates which assembly's dictionary to look in for the value associated with this key. (Overrides ResourceKey.Assembly.)
Public propertyResourceIdGets or sets a unique identifier to differentiate this key from others associated with this type.
Public propertyTypeInTargetAssemblyGets or sets the Type that defines the resource key.
Top

  NameDescription
Public methodEqualsDetermines whether the provided object is equal to the current ComponentResourceKey. (Overrides Object.Equals(Object).)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeReturns a hash code for this ComponentResourceKey. (Overrides Object.GetHashCode().)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodProvideValueReturns this ResourceKey. Instances of this class are typically used as a key in a dictionary. (Inherited from ResourceKey.)
Public methodToStringGets the string representation of a ComponentResourceKey. (Overrides Object.ToString().)
Top

For XAML information, see ComponentResourceKey Markup Extension.

This class implements an object type that is useful for creating keys that are based on types in assemblies plus an identifier. Because you define or reference the type, you do not need to request a specific ResourceDictionary, and more than one set of resources can exist in the assembly, each differentiated by the type of their ComponentResourceKey.

There are two ways to define a ComponentResourceKey.

If you want an easily accessible key, you can define a static property on your control class code that returns a ComponentResourceKey, constructed with a TypeInTargetAssembly that exists in the external resource assembly, and a ResourceId. The key can be used for defining alternate default styles for controls in an assembly, by swapping the original external resource assembly for a custom one. You can also define a named resource part within a larger control style or template to expose a customization entry point. This is particularly useful if you are defining a theme resource dictionary for your control.

You can also use the XAML ComponentResourceKey Markup Extension in verbose syntax directly to create a loose instance of the key. This is useful if you want to declare private resources from other assemblies that are less discoverable to customize.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft