DependencyObject.GetLocalValueEnumerator DependencyObject.GetLocalValueEnumerator DependencyObject.GetLocalValueEnumerator DependencyObject.GetLocalValueEnumerator Method

定义

创建一个专用的枚举数,用于确定哪些依赖项属性在此 DependencyObject 上具有以本地方式设置的值。Creates a specialized enumerator for determining which dependency properties have locally set values on this DependencyObject.

public:
 System::Windows::LocalValueEnumerator GetLocalValueEnumerator();
public System.Windows.LocalValueEnumerator GetLocalValueEnumerator ();
member this.GetLocalValueEnumerator : unit -> System.Windows.LocalValueEnumerator
Public Function GetLocalValueEnumerator () As LocalValueEnumerator

返回

一个专用的本地值枚举数。A specialized local value enumerator.

示例

下面的示例循环访问对象上设置了本地值的所有属性然后调用ClearValue,清除每个此类属性的值。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 = locallySetProperties.Current.Property;
            if (!propertyToClear.ReadOnly) { uie.ClearValue(propertyToClear); }
        }
    }
}
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

注解

一个本地值是任何依赖项属性值所设置SetValue,而不是属性系统的其他方面。A local value is any dependency property value that was set by SetValue, as opposed to other aspects of the property system.

LocalValueEnumerator获取通过调用GetLocalValueEnumerator可用于枚举具有本地设置的属性值上DependencyObject实例。The LocalValueEnumerator obtained by calling GetLocalValueEnumerator can be used to enumerate properties that have a locally set value on a DependencyObject instance. 每个此类属性表示的枚举器中LocalValueEntry具有引用特定的属性的对象DependencyProperty及其值。Each such property is represented in the enumerator by a LocalValueEntry object, which has properties that reference the specific DependencyProperty and its values. 此方法通过本地设置枚举的值可用于优化或其他处理的本地值,如确定哪些属性值的DependencyObject在清除会更改。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.

重要

返回LocalValueEnumerator可能包含LocalValueEntry是只读的依赖项属性或值通过属性系统的依赖项属性的记录。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. 例如,通过布局使用确定宽度的可视框架元素将报告为本地值ActualWidthFor example, a visual framework element that has an established width through layout will report a local value for ActualWidth. 如果为了重置它们获得本地值,检查ReadOnly上的每个属性标识符的值LocalValueEntry来确认DependencyProperty是否为只读的。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.

适用于

另请参阅