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.

DependencyObject.GetLocalValueEnumerator 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)

public LocalValueEnumerator GetLocalValueEnumerator ()
public LocalValueEnumerator GetLocalValueEnumerator ()
public function GetLocalValueEnumerator () : LocalValueEnumerator
You cannot use methods in XAML.

Return Value

A specialized local value enumerator.

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.

NoteImportant:

The returned LocalValueEnumerator might contain LocalValueEntry records for dependency properties that are read-only, or that are property values that are calculated by the property system. For example, a visual framework element that has an established width 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 first to verify that the DependencyProperty in question is not read-only.

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.

void RestoreDefaultProperties(object sender, RoutedEventArgs e)
{
    UIElementCollection uic = Sandbox.Children;
    foreach (Shape uie in uic)
    {
        LocalValueEnumerator locallySetProperties = uie.GetLocalValueEnumerator();
        while (locallySetProperties.MoveNext())
        {
            DependencyProperty propertyToClear = (DependencyProperty)locallySetProperties.Current.Property;
            if (!propertyToClear.ReadOnly) { uie.ClearValue(propertyToClear); }
        }
    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft