Raising PropertyChanged event C# with Example



Raising PropertyChanged event C# with Example

Snippet 
public class Person : INotifyPropertyChanged 
{ 
private string _address; 
public event PropertyChangedEventHandler PropertyChanged; 
private void OnPropertyChanged(string propertyName) 
{ 
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); 
} 
public string Address 
{ 
get { return _address; } 
set 
{ 
if (_address == value) 
{ 
 

return; 
} 
_address = value; 
OnPropertyChanged(nameof(Address)); 
} 
} 
} 
... 
var person = new Person(); 
person.PropertyChanged += (s,e) => Console.WriteLine(e.PropertyName); 
person.Address = "123 Fake Street"; 
Console Output 
Address 

0 Comment's

Comment Form