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. 例如, 透過配置建立寬度的 visual framework 元素會報告的本機值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.

適用於

另請參閱