Skip to content

Latest commit

 

History

History
33 lines (23 loc) · 2.01 KB

how-to-get-the-binding-object-from-a-bound-target-property.md

File metadata and controls

33 lines (23 loc) · 2.01 KB
title description ms.date helpviewer_keywords ms.assetid
How to: Get the Binding Object from a Bound Target Property
Learn how to retrieve the binding object from a data-bound target property with several provided code examples.
03/30/2017
data binding [WPF], getting binding objects from bound target properties
properties [WPF], getting binding objects from
87974c5f-136b-4de7-b07d-9285b62ab123

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 xref:System.Windows.Data.Binding object:

[!code-csharpBindValidation#GetBinding]

Note

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 xref:System.Windows.Data.BindingExpression and then get the value of the xref:System.Windows.Data.BindingExpression.ParentBinding%2A property.

For the complete example see Binding Validation Sample.

Note

If your binding is a xref:System.Windows.Data.MultiBinding, use xref:System.Windows.Data.BindingOperations.GetMultiBinding%2A?displayProperty=nameWithType. If it is a xref:System.Windows.Data.PriorityBinding, use xref:System.Windows.Data.BindingOperations.GetPriorityBinding%2A?displayProperty=nameWithType. If you are uncertain whether the target property is bound using a xref:System.Windows.Data.Binding, a xref:System.Windows.Data.MultiBinding, or a xref:System.Windows.Data.PriorityBinding, you can use xref:System.Windows.Data.BindingOperations.GetBindingBase%2A?displayProperty=nameWithType.

See also