OnPropertyChanged

+1 Orkun Erbil · January 17, 2015
I have a question.

We first set name blank [ string name = " " ; ] . To change property we set name as [ mc.Name = "Adam" ; ]. But, even if we set [ mc.Name = " " ; ],  the OnPropertyChanged method still works. Should it work or I miss something ?

Post a Reply

Replies

Oldest  Newest  Rating
+3 Eugene Botma · January 18, 2015
If you look at how OnChange events are mostly triggerd, you'll see that it should work

For example:

myclass
{
 string _datamember = "";
 public string Property
 {
   get { return _datamember;}
   set { _datamember = value; /*Trigger events*/ }
 }
}



As soon as something is assigned to Property, the events will trigger. Regardless of whether the value is different. You can of course implement something like :

set 
{
string oldval = _datamember;
_datamember = value;
if (_datamember!=oldval)
{
/*Trigger events*/
}
}

This will only trigger the onChange event when the value it receives is actually different.
  • 1

C#

107,023 followers
About

C# is an object-oriented language designed for improving the development of web applications.

Links
Moderators