导出 (0) 打印
全部展开
此文章由人工翻译。 将光标移到文章的句子上,以查看原文。
译文
原文

DependencyProperty::Register 方法 (String, Type, Type, PropertyMetadata)

使用指定的属性名称、属性类型、所有者类型和属性元数据注册依赖项属性。

命名空间:  System.Windows
程序集:  WindowsBase(在 WindowsBase.dll 中)

public:
static DependencyProperty^ Register(
	String^ name, 
	Type^ propertyType, 
	Type^ ownerType, 
	PropertyMetadata^ typeMetadata
)

参数

name
类型:System::String
要注册的依赖项对象的名称。
propertyType
类型:System::Type
属性的类型。
ownerType
类型:System::Type
正注册依赖项对象的所有者类型。
typeMetadata
类型:System.Windows::PropertyMetadata
依赖项对象的属性元数据。

返回值

类型:System.Windows::DependencyProperty
一个依赖项对象标识符,应使用它在您的类中设置 public static readonly 字段的值。 然后,在以后使用该标识符引用依赖项对象,用于某些操作,例如以编程方式设置其值,或者获取元数据。

有关依赖项对象注册的更多信息,请参见 DependencyProperty

This example shows how to back a common language runtime (CLR) property with a DependencyProperty field, thus defining a dependency property. When you define your own properties and want them to support many aspects of Windows Presentation Foundation (WPF) functionality, including styles, data binding, inheritance, animation, and default values, you should implement them as a dependency property.

The following example first registers a dependency property by calling the Register method. The name of the identifier field that you use to store the name and characteristics of the dependency property must be the Name you chose for the dependency property as part of the Register call, appended by the literal string Property. For instance, if you register a dependency property with a Name of Location, then the identifier field that you define for the dependency property must be named LocationProperty.

In this example, the name of the dependency property and its CLR accessor is State; the identifier field is StateProperty; the type of the property is Boolean; and the type that registers the dependency property is MyStateControl.

If you fail to follow this naming pattern, designers might not report your property correctly, and certain aspects of property system style application might not behave as expected.

You can also specify default metadata for a dependency property. This example registers the default value of the State dependency property to be false.

目前没有可用的代码示例或不支持该语言。

For more information about how and why to implement a dependency property, as opposed to just backing a CLR property with a private field, see 依赖项属性概述.

.NET Framework

受以下版本支持:4、3.5、3.0

.NET Framework Client Profile

受以下版本支持:4、3.5 SP1

Windows 7, Windows Vista SP1 或更高版本, Windows XP SP3, Windows Server 2008(不支持服务器核心), Windows Server 2008 R2(支持 SP1 或更高版本的服务器核心), Windows Server 2003 SP2

.NET Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

社区附加资源

添加
显示:
© 2014 Microsoft