How to correctly trigger the change of a value in a UserControl using WinForms Data Binding?
<p>I created two <code>UserControl</code>s in my WinForms application. One contains a <code>TextBox</code> (let's call this <code>TextEntryControl</code> for now) and the other one should use the value I entered into this <code>TextBox</code> to do internal stuff (enable a button and use the value when this button is clicked) - let's call this <code>TextUsingControl</code>.</p>

<p>However, I don't get this right via DataBinding.</p>

<p><strong>First (naive) approach</strong></p>

<p>I added a <code>string</code> property to <code>TextEntryControl</code> like this:</p>

<pre><code>public string MyStringProperty { get; set; }
</code></pre>

<p>Then I used the UI designer to bind the <code>TextBox</code>'s <code>Text</code> property to this <code>MyStringProperty</code>, resulting in a <code>textEntryControlBindingSource</code>. I added to the constructor right behind the <code>InitializeComponents()</code>:</p>

<pre><code>textEntryControlBindingSource.Add(this);
</code></pre>

<p>I added the same property to the <code>TextUsingControl</code>, and in my outer UI where I use the two controls, I bound the <code>TextUsingControl</code>'s string property to the one of the <code>TextEntryControl</code>, and updated the binding source appropriately:</p>

<pre><code>textEntryControlBindingSource.Add(textEntryControl1);
</code></pre>

<p>I use both controls on different tabs of a <code>TabControl</code>, and the mechanism only works once, when I first enter text into the text box and then switch to the other control.</p>

<p><strong>Next try</strong></p>

<p>I created a simple wrapper class for strings:</p>

<pre><code>public sealed class StringWrapper {

    public string Content { get; set; }
}
</code></pre>

<p>In my text entry control, I bound the text box to this string wrapper, and changed the property to look like this:</p>

<pre><code>public string MyStringProperty {
    get {
        return _stringWrapper.Content;
    }
    set {
        _stringWrapper.Content = value;
    }
}
</code></pre>

<p>I did a similar thing in the outer control with the <code>TabControl</code> - use a <code>StringWrapper</code> to bind both <code>MyStringProperty</code> of both user controls to.</p>

<p>Result: Same. But this is logical since the outer property that delegates to the wrapper doesn't get notified.</p>

<p><strong>Third try</strong></p>

<p>This one works, sort of, but I think this is an ugly workaround.</p>

<p>I ditched the <code>MyStringProperty</code> altogether and pass in the wrapper object itself via a property that, again, passes it down to the binding source:</p>

<pre><code>public StringWrapper MyStringWrapper {
    get {
        return stringWrapperBindingSource.Cast&lt;StringWrapper&gt;().FirstOrDefault();
    }
    set {
        stringWrapperBindingSource.Clear();
        if(value != null) stringWrapperBindingSource.Add(value);
    }
}
</code></pre>

<p>Now I only create one single <code>StringWrapper</code> object and set it to both user controls right after <code>InitializeComponent()</code>.</p>

<p><strong>INotifyPropertyChanged</strong></p>

<p>As a follow up: I tried <code>INotifyPropertyChanged</code> as well as described <a href="https://msdn.microsoft.com/en-us/library/ms743695%28v=vs.100%29.aspx" rel="nofollow">on MSDN.</a> This did not help either.</p>

<p><strong>What I want to achieve</strong></p>

<p>I want both user controls to have a <code>MyStringProperty</code>, and when the text I enter into <code>TextEntryControl</code>'s text box changes, the property should update and correctly notify any binding sources it is attached to.
The <code>TextUsingControl</code> should update itself when its property changes.</p>

<p>The second half is easy, I just add the appropriate logic into the <code>set</code> part of the property, but I am having trouble with the first one.</p>

<p>I am used to Eclipse's JFace Data Binding, where this functionality can be achieved with <code>PropertyChangeSupport</code> and <code>PropertyChangeListener</code> - here, I just add the appropriate event firing code to the setter and I can use <code>BeanProperties.value()</code> when setting up the data binding.</p>