我定义了一个班级CLASS
,其中包含5个成员:int A
,int B
,int C
,string D
,string E
。另外,我已使用D
将OB
CLASS
TextBlock
对象ItemTemplate
绑定到XAML中的OB
。
现在我在点击TextBlock
后尝试获取对象OB.A
,以便对OB.B
,{{1}}等做一些事情。
有谁知道如何用C#代码做到这一点?
答案 0 :(得分: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
}