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. 公开提供的键将提供公共代码路径,它起作用的属性的只读的字符,如果方法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.

另请参阅

适用于