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


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.

Equivalent WinUI method: Microsoft.UI.Xaml.DependencyProperty.Register.

 static DependencyProperty Register(winrt::hstring const & name, TypeName propertyType, TypeName ownerType, PropertyMetadata const & typeMetadata);
public static DependencyProperty Register(string name, System.Type propertyType, System.Type ownerType, PropertyMetadata typeMetadata);
function register(name, propertyType, ownerType, typeMetadata)
Public Shared Function Register (name As String, propertyType As Type, ownerType As Type, typeMetadata As PropertyMetadata) As DependencyProperty



The name of the dependency property to register.


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)).


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)).


A property metadata instance. This can contain a default value and a PropertyChangedCallback implementation reference. Passing null for this parameter is equivalent to passing a new PropertyMetadata instance created by calling PropertyMetadata.Create with null as the default value parameter.



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.


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.

Applies to

See also