Implementing INotifyPropertyChanged: is there a better way?
Hello everyone! I'm a beginner C# developer and I'm writing a simple WinForms application. I have a model class that should notify the UI about property changes. I implemented INotifyPropertyChanged, but the code turns out to be very cumbersome and repetitive.
Here's how I'm currently doing it:
```csharp
public class Person : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _name;
private int _age;
private string _address;
public string Name
{
get { return _name; }
set
{
if (_name != value)
{
_name = value;
OnPropertyChanged("Name");
}
}
}
public int Age
{
get { return _age; }
set
No answers yet.
Log in to leave an answer
Blogs