共用方式為


BindingExpression.DataItem 屬性

定義

取得這個 BindingExpression 使用的系結來源物件。

public:
 property System::Object ^ DataItem { System::Object ^ get(); };
public object DataItem { get; }
member this.DataItem : obj
Public ReadOnly Property DataItem As Object

屬性值

這個 BindingExpression 使用的系結來源物件。

範例

下列範例示範使用 GetBindingExpression 方法來取得 BindingExpressionClick 事件處理程序實作,然後呼叫 DataItem 屬性來存取系結來源物件。

TextBlock SavingsText 是系結目標物件,而其 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

適用於