DependencyProperty.Register(String, TypeName, TypeName, PropertyMetadata) DependencyProperty.Register(String, TypeName, TypeName, PropertyMetadata) DependencyProperty.Register(String, TypeName, TypeName, PropertyMetadata) DependencyProperty.Register(String, TypeName, TypeName, PropertyMetadata) Method

Definition

Registers a dependency property with the specified property name, property type, owner type, and property metadata for the property. Use this method when defining or initializing a DependencyObject derived class that will own the registered dependency property.

public : static DependencyProperty Register(Platform::String name, TypeName propertyType, TypeName ownerType, PropertyMetadata typeMetadata)
static DependencyProperty Register(winrt::hstring name, TypeName propertyType, TypeName ownerType, PropertyMetadata typeMetadata) const;
public static DependencyProperty Register(String name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata)
Public Shared Function Register(name As String, propertyType As Type, ownerType As Type, typeMetadata As PropertyMetadata) As DependencyProperty

Parameters

name
String String

The name of the dependency property to register.

propertyType
Type Type

The type of the property, as a type reference (System.Type for Microsoft .NET, a TypeName helper struct for Visual C++ component extensions (C++/CX)).

ownerType
Type Type

The owner type that is registering the dependency property, as a type reference (System.Type for Microsoft .NET, a TypeName helper struct for Visual C++ component extensions (C++/CX)).

typeMetadata
PropertyMetadata PropertyMetadata

A property metadata instance. This can contain a PropertyChangedCallback implementation reference.

Returns

A dependency property identifier that typically is stored in a public static read-only field in your DependencyObject derived class. The identifier is then used both by your own code and any third-party user code to reference the dependency property later, for operations such as setting its value programmatically or attaching a Binding in code.

Remarks

How to register a custom dependency property is described in detail (with examples) in the topic Custom dependency properties.

Registering a dependency property is typically something that you only do when an app first starts or DependencyObject derived classes defined by your app code are first used. You need to register the dependency properties early in the app lifetime to assure that other code and XAML in your app don't try to use the dependency properties before they are registered and available. Exactly how and when to register varies, based on the programming language. For C# or Microsoft Visual Basic it's common to register dependency properties during the static class initialization of the class that owns the dependency property. That way any code or XAML that initializes the instance will invoke that static construction and register the dependency property. For Visual C++ component extensions (C++/CX)), static class initialization isn't an available technique, so you typically must define an app-wide helper method that registers all the custom dependency properties that your app intends to use, as part of the Application object initialization. For examples of how and when to register custom dependency properties, including some special techniques that are needed for Visual C++ component extensions (C++/CX), see Custom dependency properties.

See also