DependencyObject.ClearValue DependencyObject.ClearValue DependencyObject.ClearValue DependencyObject.ClearValue Method

定義

清除屬性的區域數值。Clears the local value of a property.

多載

ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty)

清除屬性的區域數值。Clears the local value of a property. 要清除的屬性是由 DependencyProperty 識別項所指定。The property to be cleared is specified by a DependencyProperty identifier.

ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey)

清除唯讀屬性的區域數值。Clears the local value of a read-only property. 要清除的屬性是由 DependencyPropertyKey 所指定。The property to be cleared is specified by a DependencyPropertyKey.

ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty)

清除屬性的區域數值。Clears the local value of a property. 要清除的屬性是由 DependencyProperty 識別項所指定。The property to be cleared is specified by a DependencyProperty identifier.

public:
 void ClearValue(System::Windows::DependencyProperty ^ dp);
public void ClearValue (System.Windows.DependencyProperty dp);
member this.ClearValue : System.Windows.DependencyProperty -> unit
Public Sub ClearValue (dp As DependencyProperty)

參數

dp
DependencyProperty DependencyProperty DependencyProperty DependencyProperty

要清除的相依性屬性,該屬性是由 DependencyProperty 物件參考所識別。The dependency property to be cleared, identified by a DependencyProperty object reference.

例外狀況

範例

下列範例會逐一查看所有已在物件上設定的區域數值屬性接著會呼叫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

備註

清除屬性值,藉由呼叫ClearValue並不一定會提供相依性屬性所指定相依性屬性中繼資料中的預設值。Clearing the property value by calling ClearValue does not necessarily give a dependency property the default value that is specified in the dependency property metadata. 清除此屬性只會特別清除已套用本機的任何值。Clearing the property only specifically clears whatever local value may have been applied. 如需詳細資訊,請參閱相依性屬性值優先順序For more information, see Dependency Property Value Precedence.

另請參閱

ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey) ClearValue(DependencyPropertyKey)

清除唯讀屬性的區域數值。Clears the local value of a read-only property. 要清除的屬性是由 DependencyPropertyKey 所指定。The property to be cleared is specified by a DependencyPropertyKey.

public:
 void ClearValue(System::Windows::DependencyPropertyKey ^ key);
public void ClearValue (System.Windows.DependencyPropertyKey key);
member this.ClearValue : System.Windows.DependencyPropertyKey -> unit
Public Sub ClearValue (key As DependencyPropertyKey)

參數

key
DependencyPropertyKey DependencyPropertyKey DependencyPropertyKey DependencyPropertyKey

要清除之相依性屬性的索引鍵。The key for the dependency property to be cleared.

例外狀況

備註

ADependencyPropertyKey識別唯讀相依性屬性的屬性系統作業。A DependencyPropertyKey identifies a read-only dependency property for property system operations. 定義唯讀的相依性屬性的類別不應該公開公用存取此金鑰。Classes that define read-only dependency properties should not expose this key with public access. 公開的索引鍵會提供公用程式碼路徑,會變為負值的唯寫的字元; 屬性,如果這類方法ClearValueSetValue可能呼叫外部組件參考的索引鍵的類別。A publicly exposed key would provide a public code pathway that negated the read-only character of the property, if methods such as ClearValue or SetValue could be called outside the class or assembly, referencing the key.

清除屬性值,藉由呼叫ClearValue並不一定會提供相依性屬性所指定相依性屬性中繼資料中的預設值。Clearing the property value by calling ClearValue does not necessarily give a dependency property the default value that is specified in the dependency property metadata. 清除值只會特別清除已套用本機的任何值。Clearing the value only specifically clears whatever local value may have been applied. 如需詳細資訊,請參閱相依性屬性值優先順序For more information, see Dependency Property Value Precedence.

另請參閱

適用於