Partilhar via


Como: Get the Binding Object from a Bound Target Property

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

Exemplo

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);

Observação

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.

Para o exemplo completo, consulte Exemplo de validação de ligação.

Observação

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.

Consulte também

Tarefas

Como: Criar uma associação em código

Outros recursos

Data Binding How-to Topics