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 に答える