BindingOperations.GetBindingExpression(DependencyObject, DependencyProperty) 方法

定義

傳回與指定物件上的指定繫結目標屬性相關聯的 BindingExpression 物件。Returns the BindingExpression object associated with the specified binding target property on the specified object.

public:
 static System::Windows::Data::BindingExpression ^ GetBindingExpression(System::Windows::DependencyObject ^ target, System::Windows::DependencyProperty ^ dp);
public static System.Windows.Data.BindingExpression GetBindingExpression (System.Windows.DependencyObject target, System.Windows.DependencyProperty dp);
static member GetBindingExpression : System.Windows.DependencyObject * System.Windows.DependencyProperty -> System.Windows.Data.BindingExpression
Public Shared Function GetBindingExpression (target As DependencyObject, dp As DependencyProperty) As BindingExpression

參數

target
DependencyObject

dp 所在的繫結目標物件。The binding target object where dp is.

dp
DependencyProperty

要從中擷取 BindingExpression 物件的繫結目標屬性。The binding target property from which to retrieve the BindingExpression object.

傳回

與指定之屬性相關聯的 BindingExpression 物件,如果物件不存在,則為 nullThe BindingExpression object associated with the given property or null if none exists. 如果已針對該屬性設定 PriorityBindingExpression 物件,則會傳回 ActiveBindingExpressionIf a PriorityBindingExpression object is set on the property, the ActiveBindingExpression is returned.

例外狀況

targetdp 參數不可以是 nullThe target and dp parameters cannot be null.

範例

下列Click範例顯示GetBindingExpression使用方法取得BindingExpression的事件處理常式的執行,然後呼叫DataItem屬性來存取系結來源物件。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.

是系結目標物件,而且Text是系結目標屬性。 TextBlock SavingsTextThe TextBlockSavingsText is the binding target object and Text is the binding target property.

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

備註

BindingExpression物件會維護系結來源和系結目標之間的連接。The BindingExpression object maintains the connection between the binding source and the binding target. 您可以藉由BindingExpression呼叫此靜態方法,或FrameworkElement在資料系結GetBindingExpressionFrameworkContentElement物件上呼叫方法,來取得物件。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.

適用於

另請參閱