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

Registers a read-only dependency property, with the specified property type, owner type, property metadata, and a validation callback.

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

'Declaration
Public Shared Function RegisterReadOnly ( _
	name As String, _
	propertyType As Type, _
	ownerType As Type, _
	typeMetadata As PropertyMetadata, _
	validateValueCallback As ValidateValueCallback _
) As DependencyPropertyKey

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 user-created callback that should perform any custom validation of the dependency property value beyond typical type validation.

Return Value

Type: System.Windows.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.

This method returns the type DependencyPropertyKey, whereas RegisterAttached returns the type DependencyProperty. Typically, the keys that represent read-only properties are not made public, because the keys can be used to set the dependency property value by calling SetValue(DependencyPropertyKey, Object). Your class design will affect your requirements, but it is generally recommended to limit the access and visibility of any DependencyPropertyKey to only those parts of your code that are necessary to set that dependency property as part of class or application logic. It is also recommended that you expose a dependency property identifier for the read-only dependency property, by exposing the value of DependencyPropertyKey.DependencyProperty as a public static readonly field on your class.

Read-only dependency properties are a fairly typical scenario. You can use the value of a read-only dependency property as the basis for other property system operations that take a dependency property, such as basing a Trigger on the dependency property in a style.

For more information on dependency property registration, see DependencyProperty.

Validation on a read-only dependency property might be less important. The nonpublic access level you specify for the key reduces the likelihood for arbitrary invalid input.

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft