Hi wasimf,
I have written a sample to test your case, there is windows form in my demo, the form has two textboxes control, and bind it to a INotifyPropertyChanged derived class, I cannot recur your question, when only one textbox changed, the Property changed event will be fired only once, please check the code snippet below.
Code Snippet
INotifyPropertyChanged_Demo
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DemoCustomer d1 = DemoCustomer.CreateNewCustomer();
ArrayList ar = new ArrayList();
ar.Add(d1);
textBox1.DataBindings.Add(new Binding("Text", ar[0], "CustomerName"));
DemoCustomer d2 = DemoCustomer.CreateNewCustomer();
ar.Add(d2);
textBox2.DataBindings.Add(new Binding("Text", ar[1], "CustomerName"));
}
}
// This class implements a simple customer type
// that implements the IPropertyChange interface.
public class DemoCustomer : INotifyPropertyChanged
{
string customerName = "";
public event PropertyChangedEventHandler PropertyChanged = new PropertyChangedEventHandler(Handle_Property_Changed);
private void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
private static void Handle_Property_Changed(object sender, PropertyChangedEventArgs e)
{
MessageBox.Show(e.PropertyName + " changed");
}
// The constructor is private to enforce the factory pattern.
private DemoCustomer()
{
customerName = "no data";
}
// This is the public factory method.
public static DemoCustomer CreateNewCustomer()
{
return new DemoCustomer();
}
public string CustomerName
{
get
{
return this.customerName;
}
set
{
if (value != this.customerName)
{
this.customerName = value;
NotifyPropertyChanged("customerName");
}
}
}
}
If you still cannot figure out the bug, I think you should post the detailed code here for troubleshooting.
For your information:
http://www.codeproject.com/KB/cs/BindBetterINotifyProperty.aspx
http://www.codeproject.com/KB/cs/PropertyNotifyPart1.aspx
http://msdn2.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx
Regards,
Xun
|