Edit

Bagikan melalui


DependencyProperty.Register Method

Definition

Registers a dependency property.

Overloads

Register(String, Type, Type)

Registers a dependency property with the specified property name, property type, and owner type.

Register(String, Type, Type, PropertyMetadata)

Registers a dependency property with the specified property name, property type, owner type, and property metadata.

Register(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.

Register(String, Type, Type)

Registers a dependency property with the specified property name, property type, and owner type.

public:
 static System::Windows::DependencyProperty ^ Register(System::String ^ name, Type ^ propertyType, Type ^ ownerType);
public static System.Windows.DependencyProperty Register (string name, Type propertyType, Type ownerType);
static member Register : string * Type * Type -> System.Windows.DependencyProperty
Public Shared Function Register (name As String, propertyType As Type, ownerType As Type) As DependencyProperty

Parameters

name
String

The name of the dependency property to register. The name must be unique within the registration namespace of the owner type.

propertyType
Type

The type of the property.

ownerType
Type

The owner type that is registering the dependency property.

Returns

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.

Examples

public static readonly DependencyProperty IsDirtyProperty = DependencyProperty.Register(
  "IsDirty",
  typeof(Boolean),
  typeof(AquariumObject3)
);
Public Shared ReadOnly IsDirtyProperty As DependencyProperty = DependencyProperty.Register("IsDirty", GetType(Boolean), GetType(AquariumObject3))

Remarks

For more information on dependency property registration, see DependencyProperty.

See also

Applies to

Register(String, Type, Type, PropertyMetadata)

Registers a dependency property with the specified property name, property type, owner type, and property metadata.

public:
 static System::Windows::DependencyProperty ^ Register(System::String ^ name, Type ^ propertyType, Type ^ ownerType, System::Windows::PropertyMetadata ^ typeMetadata);
public static System.Windows.DependencyProperty Register (string name, Type propertyType, Type ownerType, System.Windows.PropertyMetadata typeMetadata);
static member Register : string * Type * Type * System.Windows.PropertyMetadata -> System.Windows.DependencyProperty
Public Shared Function Register (name As String, propertyType As Type, ownerType As Type, typeMetadata As PropertyMetadata) As DependencyProperty

Parameters

name
String

The name of the dependency property to register.

propertyType
Type

The type of the property.

ownerType
Type

The owner type that is registering the dependency property.

typeMetadata
PropertyMetadata

Property metadata for the dependency property.

Returns

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.

See also

Applies to

Register(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.

public:
 static System::Windows::DependencyProperty ^ Register(System::String ^ name, Type ^ propertyType, Type ^ ownerType, System::Windows::PropertyMetadata ^ typeMetadata, System::Windows::ValidateValueCallback ^ validateValueCallback);
public static System.Windows.DependencyProperty Register (string name, Type propertyType, Type ownerType, System.Windows.PropertyMetadata typeMetadata, System.Windows.ValidateValueCallback validateValueCallback);
static member Register : string * Type * Type * System.Windows.PropertyMetadata * System.Windows.ValidateValueCallback -> System.Windows.DependencyProperty
Public Shared Function Register (name As String, propertyType As Type, ownerType As Type, typeMetadata As PropertyMetadata, validateValueCallback As ValidateValueCallback) As DependencyProperty

Parameters

name
String

The name of the dependency property to register.

propertyType
Type

The type of the property.

ownerType
Type

The owner type that is registering the dependency property.

typeMetadata
PropertyMetadata

Property metadata for the dependency property.

validateValueCallback
ValidateValueCallback

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

Returns

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.

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

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); }
}
Public Shared ReadOnly CurrentReadingProperty As DependencyProperty =
    DependencyProperty.Register("CurrentReading",
        GetType(Double), GetType(Gauge),
        New FrameworkPropertyMetadata(Double.NaN,
            FrameworkPropertyMetadataOptions.AffectsMeasure,
            New PropertyChangedCallback(AddressOf OnCurrentReadingChanged),
            New CoerceValueCallback(AddressOf CoerceCurrentReading)),
        New ValidateValueCallback(AddressOf IsValidReading))

Public Property CurrentReading() As Double
    Get
        Return CDbl(GetValue(CurrentReadingProperty))
    End Get
    Set(ByVal value As Double)
        SetValue(CurrentReadingProperty, value)
    End Set
End Property

Remarks

For more information on dependency property registration, see DependencyProperty.

See also

Applies to