BindingOperations.ClearBinding Method

Removes the binding from a property if there is one.

Namespace:  System.Windows.Data
Assembly:  PresentationFramework (in PresentationFramework.dll)

public static void ClearBinding(
	DependencyObject target,
	DependencyProperty dp
)

Parameters

target
Type: System.Windows.DependencyObject
The object from which to remove the binding.
dp
Type: System.Windows.DependencyProperty
The dependency property from which to remove the binding.

ExceptionCondition
ArgumentNullException

The target and dp parameters cannot be null.

If the given property is data-bound with a Binding, PriorityBinding, or MultiBinding, this method removes the corresponding binding expression and restores the value of the property to what it was before any local value was set through the binding.

If the given property is not data-bound, this method has no effect.

This example shows how to clear bindings from an object.

To clear a binding from an individual property on an object, call ClearBinding as shown in the following example. The following example removes the binding from the TextProperty of mytext, a TextBlock object.


BindingOperations.ClearBinding(myText, TextBlock.TextProperty);


Clearing the binding removes the binding so that the value of the dependency property is changed to whatever it would have been without the binding. This value could be a default value, an inherited value, or a value from a data template binding.

To clear bindings from all possible properties on an object, use ClearAllBindings.

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft