Skip to main content
.NET Framework Class Library
DependencyObjectGetLocalValueEnumerator Method

Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

Namespace:   System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)
Syntax
Public Function GetLocalValueEnumerator As [%$TOPIC/ms597467_en-us_VS_110_2_0_0_0_0%]
public [%$TOPIC/ms597467_en-us_VS_110_2_0_1_0_0%] GetLocalValueEnumerator()
public:
[%$TOPIC/ms597467_en-us_VS_110_2_0_2_0_0%] GetLocalValueEnumerator()
member GetLocalValueEnumerator : unit -> [%$TOPIC/ms597467_en-us_VS_110_2_0_3_0_0%]

Return Value

Type: System.WindowsLocalValueEnumerator
A specialized local value enumerator.
Remarks

A local value is any dependency property value that was set by SetValue, as opposed to other aspects of the property system.

The LocalValueEnumerator obtained by calling GetLocalValueEnumerator can be used to enumerate properties that have a locally set value on a DependencyObject instance. Each such property is represented in the enumerator by a LocalValueEntry object, which has properties that reference the specific DependencyProperty and its values. This technique of enumerating over the locally set values can be used for optimization or for other handling of local values, such as to determine which property values of a DependencyObject would change if they were cleared.

Important noteImportant

The returned LocalValueEnumerator might contain LocalValueEntry records for dependency properties that are read-only, or dependency properties where values are calculated by the property system. For example, a visual framework element that has an established width through layout will report a local value for ActualWidth. If you are getting local values in order to reset them, check the ReadOnly value on the property identifier of each LocalValueEntry to verify that the DependencyProperty in question is not read-only.

Examples

The following example iterates all properties that have local values set on an object, then calls ClearValue to clear the values of each such property.

Private Sub RestoreDefaultProperties(ByVal sender As Object, ByVal e As RoutedEventArgs)
    Dim uic As UIElementCollection = Sandbox.Children
    For Each uie As Shape In uic
        Dim locallySetProperties As LocalValueEnumerator = uie.GetLocalValueEnumerator()
        While locallySetProperties.MoveNext()
            Dim propertyToClear As DependencyProperty = locallySetProperties.Current.Property 
            If Not propertyToClear.ReadOnly Then
                uie.ClearValue(propertyToClear)
            End If 
        End While 
    Next 
End Sub
void RestoreDefaultProperties(object sender, RoutedEventArgs e)
{
    UIElementCollection uic = Sandbox.Children;
    foreach (Shape uie in uic)
    {
        LocalValueEnumerator locallySetProperties = uie.GetLocalValueEnumerator();
        while (locallySetProperties.MoveNext())
        {
            DependencyProperty propertyToClear = locallySetProperties.Current.Property;
            if (!propertyToClear.ReadOnly) { uie.ClearValue(propertyToClear); }
        }
    }
}
Version Information

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.