BindingOperations.GetBindingExpression Method

Definition

Returns the BindingExpression object associated with the specified binding target property on the specified object.

C#
public static System.Windows.Data.BindingExpression GetBindingExpression(System.Windows.DependencyObject target, System.Windows.DependencyProperty dp);

Parameters

target
DependencyObject

The binding target object where dp is.

dp
DependencyProperty

The binding target property from which to retrieve the BindingExpression object.

Returns

The 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.

Exceptions

The target and dp parameters cannot be null.

Examples

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 TextBlock SavingsText is the binding target object and Text is the binding target property.

C#
private void OnRentRaise(Object sender, RoutedEventArgs args)
{
  // Update bills
  System.Random random = new System.Random();
  double i = random.Next(10);
  BindingExpression bindingExpression =
    BindingOperations.GetBindingExpression(SavingsText, TextBlock.TextProperty);
  SDKSample.NetIncome sourceData = (SDKSample.NetIncome) bindingExpression.DataItem;
  sourceData.Rent = (int)((1 + i / 100) * (double)sourceData.Rent);
}

Remarks

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.

Applies to

Product Versions
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also