0

我正在尝试使用反射将对象的属性绑定到文本框,传入的对象是具有公共原始类型属性的简单类和 getter/setter 中的一些代码。但是更改文本框中的值并不能反映对象实例的更改,值永远不会更新,我错过了什么?

public object myObj;

public void setObject(ref object myObject)
{
    myObj = myObject;
}

var textbox = new Textbox();
...
textbox.DataBindings.Add("Text", myObj, myObj.GetType().GetProperties()[0].Name);
this.Controls.Add(textbox);
4

1 回答 1

0

请检查这个帖子

你需要有:

  Binding myBinding = new Binding("MyDataProperty"); //name of the property on the object which is used as binding source
  myBinding.Source = myObject;
  textbox.SetBinding(TextBlock.TextProperty, myBinding);
于 2013-02-10T12:19:38.137 回答