Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

DependencyObject::SetValue Method (DependencyPropertyKey^, Object^)


Sets the local value of a read-only dependency property, specified by the DependencyPropertyKey identifier of the dependency property.

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

void SetValue(
	DependencyPropertyKey^ key,
	Object^ value


Type: System.Windows::DependencyPropertyKey^

The DependencyPropertyKey identifier of the property to set.

Type: System::Object^

The new local value.

This signature is generally used when you set values for read-only dependency properties that are defined by your custom classes. Generally, SetValue is called only from the type that registered that dependency property, which implements the internal logic that provides the determined value for the dependency property. For more information, see Read-Only Dependency Properties.

If the provided type does not match the type that is declared for the dependency property as it was originally registered, an exception is thrown. The value parameter should always be provided as the appropriate type. The exception conditions are potentially influenced by the ValidateValueCallback callback that exists on the dependency property identifier of the dependency property being set.

The following example defines a read-only dependency property, along with a public static readonly DependencyProperty that provides necessary read-only exposure to property consumers, and the get accessor for the CLR wrapper.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 3.0
Return to top
© 2017 Microsoft