Hi,
I wonder if anybody can set me straight as I am having a hard time understanding what is going on with INotifyPropertyChanged.
My understanding of the events are:
1> Have a window with 2 textfields and a button
2> Create an instance of the Employee object
5> Bind both textboxes to the Employee instance
6> The button just does ((Employee)_bs.Current).Name = "Bill"
Here is the Employee class:
public class Employee : INotifyPropertyChanged
{
public event PropertyChangedEventHandler propertyChanged;
public string Name
{
get { return _name; }
set
{
if (_name != value)
{
_name = value;
//notifyPropertyChanged();
}
}
}
public void notifyPropertyChanged([CallerMemberName] string property)
{
if (propertyChanged != null)
propertyChanged(this, new PropertyChangedEventArgs(property));
}
}
Now when I type something in textbox1 and lose focus, textbox2 is altered but when I click the button neither textbox is updated.
Obviously if I uncomment the call to notifyPropertyChanged all works fine. This however brings up questions in my mind.
1> If I change textfield1 this must be changing the datasource and then the datasource somehow triggers textbox2 to re-fetch the data then displaying it.
2> If I click the button this changes the datasource but for some reason the control isn't triggered to fetch the data again.
3> If when I uncheck the notifyPropertyChanged line, it works, but when using events I would normally assign a method to an event ie. EmployeeInstance.PropertyChanged += myMethod, and this method would update controls/properties etc.
So is there something going on in the background that I am just unaware of, if so what? Otherwise something is going wrong in my head!
I hope that I have explained myself well enough and someone can put me straight.
Thanks