0

我定义了一个类CLASS,其中包含 5 个成员:int Aint Bint Cstring Dstring ED此外OB,我已经CLASS使用.TextBlockItemTemplate

现在我试图OB在单击 后获取对象,TextBlock以便对等做一些事情。有谁知道如何在 C# 代码中做到这一点?OB.AOB.B

4

1 回答 1

0
private void myTextBlock_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    var myTextBlock = sender as TextBlock;

    if (myTextBlock == null) return;

    BindingExpression binding = myTextBlock.GetBindingExpression(TextBlock.TextProperty);
    CLASS BindedInstance = binding.ResolvedSource as CLASS; // Equals to OB object

    BindedInstance.A = ... /// Do whatever you want with the rest of properties
}
于 2013-10-22T04:33:45.287 回答