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 |
|
87974c5f-136b-4de7-b07d-9285b62ab123 |
This example shows how to obtain the binding object from a data-bound target property.
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.