DependencyProperty.Register Method (String, Type, Type, PropertyMetadata)
Registers a dependency property with the specified property name, property type, owner type, and property metadata.
Assembly: WindowsBase (in WindowsBase.dll)
static member Register : name:string * propertyType:Type * ownerType:Type * typeMetadata:PropertyMetadata -> DependencyProperty
- Type: System.String
The name of the dependency property to register.
- Type: System.Type
The type of the property.
- Type: System.Type
The owner type that is registering the dependency property.
- Type: System.Windows.PropertyMetadata
Property metadata for the dependency property.
Return ValueType: System.Windows.DependencyProperty
A dependency property identifier that should be used to set the value of a public static readonly field in your class. That identifier is then used to reference the dependency property later, for operations such as setting its value programmatically or obtaining metadata.
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 Dependency Properties Overview.
Windows 8.1, Windows Server 2012 R2, 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.