I have made a test application using Winforms and C#. 2 textbox's Text properties are bound to the same custome property. custom property implements an event PropertyChangedEventHandler as is described in this post.
the issue is that then I modify one of the textboxes Taxt value, the other gets modified too. but thats not true if I modify the property they are bound to.
Here is the code:
public partial class Form1 : Form
{
private string _text;
public string TextProperty
{
get
{
return _text;
}
set
{
_text = value;
InvokePropertyChanged();
}
}
#region implement event
private event PropertyChangedEventHandler PropertyChanged;
private void InvokePropertyChanged([CallerMemberName]string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion implement event
public Form1()
{
InitializeComponent();
textBox1.DataBindings.Add("Text", this, "TextProperty", false, DataSourceUpdateMode.OnPropertyChanged);
textBox2.DataBindings.Add("Text", this, "TextProperty", false, DataSourceUpdateMode.OnPropertyChanged);
}
private void button1_Click(object sender, EventArgs e)
{
TextProperty = "text is not changin in textBox Controls";
}
}
can somebody help to understand the issue. here
why TextProperty = "text is not changin in textBox Controls";
doesn't update the controls?