Information
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.

DependencyProperty.UnsetValue Field

Specifies a static value that is used by the property system rather than null to indicate that the property exists, but does not have its value set by the property system.

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

public static readonly Object UnsetValue

Field Value

Type: System.Object
The sentinel value for an unset value.

UnsetValue is a sentinel value that is used for scenarios where the property system is unable to determine a requested DependencyProperty value. UnsetValue is used rather than null, because null could be a valid property value, as well as a valid (and frequently used) default value. UnsetValue should not be returned out of GetValue. When you call GetValue on a dependency property on a DependencyObject, one of the following applies:

  • A dependency property has a default value established, and that value is returned.

  • Some other value was established by the property system, and the default value is no longer relevant. For details, see Dependency Property Value Precedence.

ReadLocalValue returns UnsetValue when the requested property has not been locally set.

Important noteImportant Note:

Do not register a dependency property with the specific default value of UnsetValue. This will be confusing for property consumers and will have unintended consequences within the property system.

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.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft