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

備註

A區域數值是所設定的任何相依性屬性值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.

適用於

另請參閱