Export (0) Print
Expand All

BindingOperations.GetBindingExpression Method

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

Namespace: System.Windows.Data
Assembly: PresentationFramework (in presentationframework.dll)

public static BindingExpression GetBindingExpression (
	DependencyObject target,
	DependencyProperty dp
)
public static BindingExpression GetBindingExpression (
	DependencyObject target, 
	DependencyProperty dp
)
public static function GetBindingExpression (
	target : DependencyObject, 
	dp : DependencyProperty
) : BindingExpression
You cannot use methods in XAML.

Parameters

target
dp

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

Return Value

The BindingExpression object associated with the given property or a null reference (Nothing in Visual Basic) if none exists. If a PriorityBindingExpression object is set on the property, the ActiveBindingExpression is returned.

Exception typeCondition

ArgumentNullException

The target and dp parameters cannot be a null reference (Nothing in Visual Basic).

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.

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

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show:
© 2014 Microsoft