DependencyProperty..::.UnsetValue Field Home
This page is specific to:Microsoft Version:3.03.5Silverlight 34.0
.NET Framework Class Library for Silverlight
DependencyProperty..::.UnsetValue Field

Specifies a static value that is used by the property system rather than nullNothingnullptra null reference (Nothing in Visual Basic) 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)
Syntax

'Usage

Dim value As Object

value = DependencyProperty.UnsetValue


'Declaration

Public Shared ReadOnly UnsetValue As Object

Field Value

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

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 nullNothingnullptra null reference (Nothing in Visual Basic), because nullNothingnullptra null reference (Nothing in Visual Basic) 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.

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

Other Resources

© 2009 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