DependencyObject.ClearValue method

Applies to Windows and Windows Phone

Clears the local value of a dependency property.

Syntax

Public Sub ClearValue(
  dp As DependencyProperty 
)

Parameters

dp

Type: DependencyProperty

The DependencyProperty identifier of the property for which to clear the value.

Remarks

ClearValue is sometimes used as part of a property-changed callback method. For more info, see Custom dependency properties.

Examples

This example checks for an existing local value with ReadLocalValue. If there is a local value, as indicated by not returning UnsetValue, then the existing local value is removed by calling ClearValue.

Public Shared Function ClearSetProperty(targetObject As DependencyObject, targetDP As DependencyProperty) As Boolean
    If targetObject Is Nothing Or targetDP Is Nothing Then
        Throw New ArgumentNullException()
    End If
    Dim localValue As Object = targetObject.ReadLocalValue(targetDP)
    If localValue = DependencyProperty.UnsetValue Then
        ClearSetProperty = False
    Else
        targetObject.ClearValue(targetDP)
        ClearSetProperty = True
    End If
End Function

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd

See also

DependencyObject
Dependency properties overview

 

 

Show:
© 2014 Microsoft