BindingOperations.GetBindingExpression Method (DependencyObject, DependencyProperty)
Returns the BindingExpression object associated with the specified binding target property on the specified object.
Assembly: PresentationFramework (in PresentationFramework.dll)
Public Shared Function GetBindingExpression ( target As DependencyObject, dp As DependencyProperty ) As BindingExpression
Parameters
- target
-
Type:
System.Windows.DependencyObject
The binding target object where dp is.
- dp
-
Type:
System.Windows.DependencyProperty
The binding target property from which to retrieve the BindingExpression object.
Return Value
Type: System.Windows.Data.BindingExpressionThe BindingExpression object associated with the given property or null if none exists. If a PriorityBindingExpression object is set on the property, the ActiveBindingExpression is returned.
| Exception | Condition |
|---|---|
| ArgumentNullException | The target and dp parameters cannot be null. |
The BindingExpression object maintains the connection between the binding source and the binding target. You can obtain the BindingExpression object by calling this static method or by calling the GetBindingExpression method on a data-bound FrameworkElement or FrameworkContentElement object.
The following example shows the implementation of a Click event handler that uses the GetBindingExpression method to obtain the BindingExpression and then calls the DataItem property to access the binding source object.
The TextBlockSavingsText is the binding target object and Text is the binding target property.
Private Sub OnRentRaise(ByVal sender As Object, ByVal args As RoutedEventArgs) Dim _random As New System.Random() Dim num1 As Double = _random.Next(10) Dim expression1 As BindingExpression = BindingOperations.GetBindingExpression(Me.SavingsText, TextBlock.TextProperty) Dim income1 As NetIncome = DirectCast(expression1.DataItem, NetIncome) income1.Rent = CInt(((1 + (num1 / 100)) * income1.Rent)) End Sub
Available since 3.0