.NET Framework Class Library for Silverlight
DependencyObject..::.ReadLocalValue Method

Returns the local value of a dependency property, if a local value is set.

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

Visual Basic (Declaration)
Public Function ReadLocalValue ( _
    dp As DependencyProperty _
) As Object
Visual Basic (Usage)
Dim instance As DependencyObject
Dim dp As DependencyProperty
Dim returnValue As Object

returnValue = instance.ReadLocalValue(dp)
C#
public Object ReadLocalValue(
    DependencyProperty dp
)

Parameters

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

Return Value

Type: System..::.Object
Returns the local value, or returns the sentinel value UnsetValue if no local value is set.
Remarks

You should use the CLR wrappers, or GetValue, for most typical "get" operations for a dependency property. ReadLocalValue does not return the effective value for a variety of circumstances where the value was not locally set.

Values that are set by styles, templates, default value, or property value inheritance are not considered to be local values. However, bindings and other expressions are considered to be local values, after they have been evaluated.

When no local value is set, this method returns UnsetValue.

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.

C#
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

Tags :


Page view tracker