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 方法获取 BindingExpression,然后调用 DataItem 属性来访问绑定源对象的 Click 事件处理程序的实现。

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

适用于