Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

DependencyObject.ClearValue Method

Clears the local value of a dependency property.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
public void ClearValue(
	DependencyProperty dp
)

Parameters

dp
Type: System.Windows.DependencyProperty
The DependencyProperty identifier of the property to clear the value for.

Clearing the property value by calling ClearValue does not necessarily give a dependency property its default value. Clearing the property only specifically clears whatever local value may have been applied, but other factors in dependency property precedence (such as styles, or an animation) might still be applying a value. For more information on the value precedence concept, see Dependency Property Value Precedence.

The following 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 static bool ClearSetProperty(DependencyObject targetObject, DependencyProperty targetDP)
{
    if (targetObject == null || targetDP == null)
    {
        throw new ArgumentNullException();
    }
    object localValue = targetObject.ReadLocalValue(targetDP);
    if (localValue == DependencyProperty.UnsetValue)
    {
        return false;
    }
    else
    {
        targetObject.ClearValue(targetDP);
        return true;
    }
}


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.