title: Two-Way databinding dynamic object on winform controls
body: <p>I want to databind a Dynamic object to a control in a winform app. So far I got it somewhat working, it does seems to databind "the first time", <strong>but then when I change the property value it does not take effect on the binded control</strong>, and that's the problem I can't overcome.</p>
  
  <p>Here is the code, if you create a new winform app with a textbox and a button you can test it:</p>
  
  <pre><code>public partial class Form1 : Form
      {
          public dynamic ViewData { get; set; }
  
          public Form1()
          {
              InitializeComponent();
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
  
              this.ViewData = new ExpandoObject();
  
              this.ViewData.Test = "test1";
  
              var bind = new Binding("Text", this.ViewData, null);
              bind.Format += (o, c) =&gt; c.Value = this.ViewData.Test;
              bind.Parse += (o, c) =&gt; this.ViewData.Test = c.Value;
              textBox1.DataBindings.Add(bind);
  
              this.ViewData.Test = "test2";
  
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
              this.ViewData.Test = "test3";
          }
      }
  </code></pre>
  
  <p>For the record, if I change the control value, it'd reflected on the dynamic property, which is OK too. </p>
  
  <p>For the sake of completeness, <a href="https://stackoverflow.com/questions/15375945/binding-custom-properties-values-of-an-instance-of-expandoobject-to-a-net-wind">This post</a> gave me this approach.</p>