DependencyObject..::.ClearValue Method
This page is specific to:Microsoft Version:
3.03.5Silverlight 34
.NET Framework Class Library for Silverlight
DependencyObject..::.ClearValue Method

Clears the local value of a dependency property.

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

'Usage

Dim instance As DependencyObject
Dim dp As DependencyProperty

instance.ClearValue(dp)

'Declaration

Public Sub ClearValue ( _
    dp As DependencyProperty _
)

Parameters

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

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 this concept, see Dependency Property Value Precedence.

Examples

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;
    }
}


Platforms

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

See Also

Reference

© 2010 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View