SetValue Method (DependencyProperty, Object)

DependencyObject.SetValue Method (DependencyProperty, Object)


Sets the local value of a dependency property, specified by its dependency property identifier.

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

member SetValue : 
        dp:DependencyProperty *
        value:Object -> unit


Type: System.Windows.DependencyProperty

The identifier of the dependency property to set.

Type: System.Object

The new local value.

Exception Condition

Attempted to modify a read-only dependency property, or a property on a sealed DependencyObject.


value was not the correct type as registered for the dp property.

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. Otherwise, the value provided might be failing general type-checking conditions (for example, passing a string when the native type is Double).

.NET Framework
Available since 3.0
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
© 2015 Microsoft