.NET Framework Class Library
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)
Syntax

Visual Basic (Declaration)
Public Shared Function Register ( _
    name As String, _
    propertyType As Type, _
    ownerType As Type, _
    typeMetadata As PropertyMetadata, _
    validateValueCallback As ValidateValueCallback _
) As DependencyProperty
Visual Basic (Usage)
Dim name As String
Dim propertyType As Type
Dim ownerType As Type
Dim typeMetadata As PropertyMetadata
Dim validateValueCallback As ValidateValueCallback
Dim returnValue As DependencyProperty

returnValue = DependencyProperty.Register(name, _
    propertyType, ownerType, typeMetadata, _
    validateValueCallback)
C#
public static DependencyProperty Register(
    string name,
    Type propertyType,
    Type ownerType,
    PropertyMetadata typeMetadata,
    ValidateValueCallback validateValueCallback
)
Visual C++
public:
static DependencyProperty^ Register(
    String^ name, 
    Type^ propertyType, 
    Type^ ownerType, 
    PropertyMetadata^ typeMetadata, 
    ValidateValueCallback^ validateValueCallback
)
JScript
public static function Register(
    name : String, 
    propertyType : Type, 
    ownerType : Type, 
    typeMetadata : PropertyMetadata, 
    validateValueCallback : ValidateValueCallback
) : DependencyProperty
XAML
You cannot use methods in XAML.

Parameters

name
Type: System..::.String
The name of the dependency property to register.
propertyType
Type: System..::.Type
The type of the property.
ownerType
Type: System..::.Type
The owner type that is registering the dependency property.
typeMetadata
Type: System.Windows..::.PropertyMetadata
Property metadata for the dependency property.
validateValueCallback
Type: System.Windows..::.ValidateValueCallback
A reference to a callback that should perform any custom validation of the dependency property value beyond typical type validation.

Return Value

Type: 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.
Remarks

For more information on dependency property registration, see DependencyProperty.

Examples

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

C#
public static readonly DependencyProperty CurrentReadingProperty = DependencyProperty.Register(
    "CurrentReading",
    typeof(double),
    typeof(Gauge),
    new FrameworkPropertyMetadata(
        Double.NaN,
        FrameworkPropertyMetadataOptions.AffectsMeasure,
        new PropertyChangedCallback(OnCurrentReadingChanged),
        new CoerceValueCallback(CoerceCurrentReading)
    ),
    new ValidateValueCallback(IsValidReading)
);
public double CurrentReading
{
  get { return (double)GetValue(CurrentReadingProperty); }
  set { SetValue(CurrentReadingProperty, value); }
}
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0
See Also

Reference

Other Resources

Tags :


Page view tracker