This documentation is archived and is not being maintained.

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

Registers a dependency property with the specified property name, property type, owner type, property metadata, and a value validation callback for the property.

Namespace: System.Windows
Assembly: WindowsBase (in windowsbase.dll)

public static DependencyProperty Register (
	string name,
	Type propertyType,
	Type ownerType,
	PropertyMetadata typeMetadata,
	ValidateValueCallback validateValueCallback
public static DependencyProperty Register (
	String name, 
	Type propertyType, 
	Type ownerType, 
	PropertyMetadata typeMetadata, 
	ValidateValueCallback validateValueCallback
public static function Register (
	name : String, 
	propertyType : Type, 
	ownerType : Type, 
	typeMetadata : PropertyMetadata, 
	validateValueCallback : ValidateValueCallback
) : DependencyProperty
You cannot use methods in XAML.



The name of the dependency property to register.


The type of the property.


The owner type that is registering the dependency property.


Property metadata for the dependency property.


A reference to a callback that should perform any custom validation of the dependency property value beyond typical type validation.

Return Value

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.

For more information on dependency property registration, see DependencyProperty.

The following example registers a dependency property, including a validation callback (the callback definition is not shown; for details on the callback definition, see ValidateValueCallback).

public static readonly DependencyProperty CurrentReadingProperty = DependencyProperty.Register(
    new FrameworkPropertyMetadata(
        new PropertyChangedCallback(OnCurrentReadingChanged),
        new CoerceValueCallback(CoerceCurrentReading)
    new ValidateValueCallback(IsValidReading)
public double CurrentReading
  get { return (double)GetValue(CurrentReadingProperty); }
  set { SetValue(CurrentReadingProperty, value); }

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0