Freigeben über


How to: Get the Binding Object from a Bound Target Property

This example shows how to obtain the binding object from a data-bound target property.

Example

You can do the following to get the Binding object:

// textBox3 is an instance of a TextBox
// the TextProperty is the data-bound dependency property
Binding myBinding = BindingOperations.GetBinding(textBox3, TextBox.TextProperty);
NoteNote:

You must specify the dependency property for the binding you want because it is possible that more than one property of the target object is using data binding.

Alternatively, you can get the BindingExpression and then get the value of the ParentBinding property.

For the complete example see Binding Validation Sample.

NoteNote:

If your binding is a MultiBinding, use BindingOperations.GetMultiBinding. If it is a PriorityBinding, use BindingOperations.GetPriorityBinding. If you are uncertain whether the target property is bound using a Binding, a MultiBinding, or a PriorityBinding, you can use BindingOperations.GetBindingBase.

See Also

Tasks

How to: Create a Binding in Code

Other Resources

Data Binding Samples
Data Binding How-to Topics