BindingOperations.GetBindingExpression メソッド

定義

指定されたオブジェクト上の指定されたバインディング ターゲット プロパティに関連付けられた BindingExpression オブジェクトを返します。

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 が存在するバインディング ターゲット オブジェクト。

dp
DependencyProperty

BindingExpression オブジェクトの取得元となるバインディング ターゲット プロパティ。

戻り値

特定のプロパティに関連付けられている BindingExpression オブジェクト、または存在しない場合は nullPriorityBindingExpression オブジェクトがプロパティに設定されている場合は、ActiveBindingExpression が返されます。

例外

target パラメーターと dp パラメーターを null にすることはできません。

次の例は、 メソッドを Click 使用して を GetBindingExpression 取得 BindingExpression し、 プロパティを呼び出 DataItem してバインディング ソース オブジェクトにアクセスするイベント ハンドラーの実装を示しています。

TextBlockSavingsTextはバインディング ターゲット オブジェクトであり、Textバインド ターゲット プロパティです。

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 、バインディング ソースとバインド ターゲットの間の接続を維持します。 オブジェクトを取得するには、この静的メソッドを BindingExpression 呼び出すか、 GetBindingExpression データバインド FrameworkElement または FrameworkContentElement オブジェクトで メソッドを呼び出します。

適用対象

こちらもご覧ください