ComponentResourceKey 类


定义或引用基于外部程序集中的类名以及一个附加标识符的资源键。Defines or references resource keys based on class names in external assemblies, as well as an additional identifier.

public ref class ComponentResourceKey : System::Windows::ResourceKey
public class ComponentResourceKey : System.Windows.ResourceKey
type ComponentResourceKey = class
    inherit ResourceKey
Public Class ComponentResourceKey
Inherits ResourceKey


有关 XAML 信息,请参阅 ComponentResourceKey 标记扩展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. 由于你定义或引用了类型,因此你不需要请求特定的 ResourceDictionary ,并且程序集中可能存在多个资源集,每个资源集都可以根据其类型进行区分 ComponentResourceKeyBecause 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.

可以通过两种方法来定义 ComponentResourceKeyThere are two ways to define a ComponentResourceKey.

如果需要易于访问的密钥,可以在控件类代码上定义一个静态属性,该属性将返回 ComponentResourceKeyTypeInTargetAssembly 并使用外部资源程序集中存在的来构造 ResourceIdIf 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.

还可以直接在详细语法中使用 XAML ComponentResourceKey 标记扩展 来创建密钥的松散实例。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.



初始化 ComponentResourceKey 类的新实例。Initializes a new instance of the ComponentResourceKey class.

ComponentResourceKey(Type, Object)

初始化 ComponentResourceKey 类的新实例,并指定用于定义键的 Type 以及用作附加资源标识符的对象。Initializes a new instance of a ComponentResourceKey , specifying the Type that defines the key, and an object to use as an additional resource identifier.



获取程序集对象,该对象指示要在哪个程序集的字典中查找与此键关联的值。Gets the assembly object that indicates which assembly's dictionary to look in for the value associated with this key.


获取或设置一个唯一标识符,以便将此键与该类型的其他关联键区分开。Gets or sets a unique identifier to differentiate this key from others associated with this type.


获取或设置定义资源键的 TypeGets or sets the Type that defines the resource key.



确定提供的对象是否等于当前 ComponentResourceKeyDetermines whether the provided object is equal to the current ComponentResourceKey.


返回此 ComponentResourceKey 的哈希代码。Returns a hash code for this ComponentResourceKey.


获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)

返回此 ResourceKeyReturns this ResourceKey. 此类的实例通常用作字典中的键。Instances of this class are typically used as a key in a dictionary.

(继承自 ResourceKey)

获取 ComponentResourceKey 的字符串表示形式。Gets the string representation of a ComponentResourceKey.