Επεξεργασία

Κοινή χρήση μέσω


DependencyObject.ClearValue Method

Definition

Clears the local value of a property.

Overloads

ClearValue(DependencyProperty)

Clears the local value of a property. The property to be cleared is specified by a DependencyProperty identifier.

ClearValue(DependencyPropertyKey)

Clears the local value of a read-only property. The property to be cleared is specified by a DependencyPropertyKey.

ClearValue(DependencyProperty)

Clears the local value of a property. 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)

Parameters

dp
DependencyProperty

The dependency property to be cleared, identified by a DependencyProperty object reference.

Exceptions

Examples

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

Remarks

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.

See also

Applies to

ClearValue(DependencyPropertyKey)

Clears the local value of a read-only property. 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)

Parameters

key
DependencyPropertyKey

The key for the dependency property to be cleared.

Exceptions

Remarks

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. 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.

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.

See also

Applies to