Class DependencyProperty
Represents a dependency property that is registered with the Silverlight dependency property system. Dependency properties provide support for value expressions, data binding, animation, and property change notification.
Inheritance
Inherited Members
Namespace: System.Windows
Assembly: OpenSilver.dll
Syntax
public class DependencyProperty
Fields
| Improve this Doc View SourceUnsetValue
Specifies a static value that is used by the property system rather than null to indicate that the property exists, but does not have its value set by the property system.
Declaration
public static readonly object UnsetValue
Field Value
Type | Description |
---|---|
System.Object | The sentinel value for an unset value. |
Properties
| Improve this Doc View SourceDefaultMetadata
Gets the default metadata of the DependencyProperty.
Declaration
public PropertyMetadata DefaultMetadata { get; }
Property Value
Type | Description |
---|---|
PropertyMetadata |
GlobalIndex
Gets an internally generated value that uniquely identifies the DependencyProperty.
Declaration
public int GlobalIndex { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
IsAttached
Declaration
public bool IsAttached { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Name
Gets the name of the DependencyProperty.
Declaration
public string Name { get; }
Property Value
Type | Description |
---|---|
System.String |
OwnerType
Gets the type of the object that registered the DependencyProperty with the property system, or added itself as owner of the property.
Declaration
public Type OwnerType { get; }
Property Value
Type | Description |
---|---|
System.Type |
PropertyType
Gets the type that the DependencyProperty uses for its value.
Declaration
public Type PropertyType { get; }
Property Value
Type | Description |
---|---|
System.Type |
ReadOnly
Gets a value that indicates whether the dependency property identified by this DependencyProperty instance is a read-only dependency property.
Declaration
public bool ReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean | true if the dependency property is read-only; otherwise, false. |
ValidateValueCallback
Gets the value validation callback for the DependencyProperty.
Declaration
public ValidateValueCallback ValidateValueCallback { get; }
Property Value
Type | Description |
---|---|
ValidateValueCallback |
Methods
| Improve this Doc View SourceAddOwner(Type)
Adds another type as an owner of a dependency property that has already been registered.
Declaration
public DependencyProperty AddOwner(Type ownerType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | ownerType | The type to add as an owner of this dependency property. |
Returns
Type | Description |
---|---|
DependencyProperty | A reference to the original DependencyProperty identifier that identifies the dependency property. This identifier should be exposed by the adding class as a public static readonly field. |
AddOwner(Type, PropertyMetadata)
Adds another type as an owner of a dependency property that has already been registered, providing dependency property metadata for the dependency property as it will exist on the provided owner type.
Declaration
public DependencyProperty AddOwner(Type ownerType, PropertyMetadata typeMetadata)
Parameters
Type | Name | Description |
---|---|---|
System.Type | ownerType | The type to add as owner of this dependency property. |
PropertyMetadata | typeMetadata | The metadata that qualifies the dependency property as it exists on the provided type. |
Returns
Type | Description |
---|---|
DependencyProperty | A reference to the original DependencyProperty identifier that identifies the dependency property. This identifier should be exposed by the adding class as a public static readonly field. |
GetMetadata(Type)
Retrieves the property metadata value for the dependency property as registered to the specified System.Type.
Declaration
public PropertyMetadata GetMetadata(Type forType)
Parameters
Type | Name | Description |
---|---|---|
System.Type | forType | The specific type from which to retrieve the dependency property metadata. |
Returns
Type | Description |
---|---|
PropertyMetadata | A property metadata object. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException |
|
IsValidType(Object)
Determines whether a specified value is acceptable for this dependency property's type, as checked against the property type provided in the original dependency property registration.
Declaration
public bool IsValidType(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | The value to check. |
Returns
Type | Description |
---|---|
System.Boolean | true if the specified value is the registered property type or an acceptable derived type; otherwise, false. |
IsValidValue(Object)
Determines whether the provided value is accepted for the type of property through basic type checking, and also potentially if it is within the allowed range of values for that type.
Declaration
public bool IsValidValue(object value)
Parameters
Type | Name | Description |
---|---|---|
System.Object | value | The value to check. |
Returns
Type | Description |
---|---|
System.Boolean | true if the value is acceptable and is of the correct type or a derived type; otherwise, false. |
OverrideMetadata(Type, PropertyMetadata)
Specifies alternate metadata for this dependency property when it is present on instances of a specified type, overriding the metadata that existed for the dependency property as it was inherited from base types.
Declaration
public void OverrideMetadata(Type forType, PropertyMetadata typeMetadata)
Parameters
Type | Name | Description |
---|---|---|
System.Type | forType | The type where this dependency property is inherited and where the provided alternate metadata will be applied. |
PropertyMetadata | typeMetadata | The metadata to apply to the dependency property on the overriding type. |
Exceptions
Type | Condition |
---|---|
System.InvalidOperationException | An attempt was made to override metadata on a read-only dependency property (that operation cannot be done using this signature). |
OverrideMetadata(Type, PropertyMetadata, DependencyPropertyKey)
Supplies alternate metadata for a read-only dependency property when it is present on instances of a specified type, overriding the metadata that was provided in the initial dependency property registration. You must pass the DependencyPropertyKey for the read-only dependency property to avoid raising an exception.
Declaration
public void OverrideMetadata(Type forType, PropertyMetadata typeMetadata, DependencyPropertyKey key)
Parameters
Type | Name | Description |
---|---|---|
System.Type | forType | The type where this dependency property is inherited and where the provided alternate metadata will be applied. |
PropertyMetadata | typeMetadata | The metadata to apply to the dependency property on the overriding type. |
DependencyPropertyKey | key | The access key for a read-only dependency property. |
Register(String, Type, Type, PropertyMetadata)
Registers a dependency property with the specified property name, property type, owner type, and property metadata for the property.
Declaration
public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the dependency property to register. |
System.Type | propertyType | The type of the property. |
System.Type | ownerType | The owner type that is registering the dependency property. |
PropertyMetadata | typeMetadata | A property metadata instance. This can contain a PropertyChangedCallback implementation reference. |
Returns
Type | Description |
---|---|
DependencyProperty | A dependency property identifier that should be used to set the value of a public static readonly field in your 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. |
Exceptions
Type | Condition |
---|---|
System.ArgumentNullException | A required parameter was null (check the exception for the name of the missing parameter). |
System.ArgumentException | A parameter was out of range, for instance name was an empty string.-or-Attempted to register with a propertyType that does not match a default value specified in the typeMetadata. |
Register(String, Type, Type, PropertyMetadata, ValidateValueCallback)
Register a Dependency Property
Declaration
public static DependencyProperty Register(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | Name of property |
System.Type | propertyType | Type of the property |
System.Type | ownerType | Type that is registering the property |
PropertyMetadata | typeMetadata | Metadata to use if current type doesn't specify type-specific metadata |
ValidateValueCallback | validateValueCallback | Provides additional value validation outside automatic type validation |
Returns
Type | Description |
---|---|
DependencyProperty | Dependency Property |
RegisterAttached(String, Type, Type, PropertyMetadata)
Registers an attached dependency property with the specified property name, property type, owner type, and property metadata for the property.
Declaration
public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the dependency property to register. |
System.Type | propertyType | The type of the property. |
System.Type | ownerType | The owner type that is registering the dependency property. |
PropertyMetadata | defaultMetadata | A property metadata instance. This can contain a PropertyChangedCallback implementation reference. |
Returns
Type | Description |
---|---|
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 attached property later, for operations such as setting its value programmatically, or attaching a Binding. |
RegisterAttached(String, Type, Type, PropertyMetadata, ValidateValueCallback)
Registers an attached property with the specified property type, owner type, property metadata, and value validation callback for the property.
Declaration
public static DependencyProperty RegisterAttached(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the dependency property to register. |
System.Type | propertyType | The type of the property. |
System.Type | ownerType | The owner type that is registering the dependency property. |
PropertyMetadata | defaultMetadata | Property metadata for the dependency property. This can include the default value as well as other characteristics. |
ValidateValueCallback | validateValueCallback | A reference to a callback that should perform any custom validation of the dependency property value beyond typical type validation. |
Returns
Type | Description |
---|---|
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. |
RegisterAttachedReadOnly(String, Type, Type, PropertyMetadata)
Registers a read-only attached property, with the specified property type, owner type, and property metadata.
Declaration
public static DependencyPropertyKey RegisterAttachedReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the dependency property to register. |
System.Type | propertyType | The type of the property. |
System.Type | ownerType | The owner type that is registering the dependency property. |
PropertyMetadata | defaultMetadata | Property metadata for the dependency property. |
Returns
Type | Description |
---|---|
DependencyPropertyKey | A dependency property key that should be used to set the value of a static read-only field in your class, which is then used to reference the dependency property later. |
RegisterAttachedReadOnly(String, Type, Type, PropertyMetadata, ValidateValueCallback)
Registers a read-only attached property, with the specified property type, owner type, property metadata, and a validation callback.
Declaration
public static DependencyPropertyKey RegisterAttachedReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata defaultMetadata, ValidateValueCallback validateValueCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the dependency property to register. |
System.Type | propertyType | The type of the property. |
System.Type | ownerType | The owner type that is registering the dependency property. |
PropertyMetadata | defaultMetadata | Property metadata for the dependency property. |
ValidateValueCallback | validateValueCallback | A reference to a user-created callback that should perform any custom validation of the dependency property value beyond typical type validation. |
Returns
Type | Description |
---|---|
DependencyPropertyKey | A dependency property key that should be used to set the value of a static read-only field in your class, which is then used to reference the dependency property. |
RegisterReadOnly(String, Type, Type, PropertyMetadata)
Registers a read-only dependency property, with the specified property type, owner type, and property metadata.
Declaration
public static DependencyPropertyKey RegisterReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The name of the dependency property to register. |
System.Type | propertyType | The type of the property. |
System.Type | ownerType | The owner type that is registering the dependency property. |
PropertyMetadata | typeMetadata | Property metadata for the dependency property. |
Returns
Type | Description |
---|---|
DependencyPropertyKey | A dependency property key that should be used to set the value of a static read-only field in your class, which is then used to reference the dependency property. |
RegisterReadOnly(String, Type, Type, PropertyMetadata, ValidateValueCallback)
Simple registration, metadata, validation, and a read-only property key. Calling this version restricts the property such that it can only be set via the corresponding overload of DependencyObject.SetValue.
Declaration
public static DependencyPropertyKey RegisterReadOnly(string name, Type propertyType, Type ownerType, PropertyMetadata typeMetadata, ValidateValueCallback validateValueCallback)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | |
System.Type | propertyType | |
System.Type | ownerType | |
PropertyMetadata | typeMetadata | |
ValidateValueCallback | validateValueCallback |
Returns
Type | Description |
---|---|
DependencyPropertyKey |
ToString()
Returns the string representation of the DependencyProperty.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String |