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.

异常

注解

DependencyPropertyKey标识属性系统操作的只读依赖属性。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. 公开密钥将提供一个非属性的只读字符的公共代码路径, 前提是可以在类或程序集的外部ClearValue调用SetValue方法 (如或), 并引用密钥。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.

另请参阅

适用于