Skip to content

Instantly share code, notes, and snippets.

@MichaelaIvanova
Created August 29, 2016 14:32
Show Gist options
  • Save MichaelaIvanova/b65e773bb2c88db8a2e7be4a4c696b86 to your computer and use it in GitHub Desktop.
Save MichaelaIvanova/b65e773bb2c88db8a2e7be4a4c696b86 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notifier
{
public class Person : INotifyPropertyChanged
{
private string _name;
private string _lastName;
private string _address;
public string Name
{
get { return this._name; }
set
{
this._name = value;
NotifyPropertyChanged("Name");
}
}
public string LastName
{
get { return this._lastName; }
set
{
this._lastName = value;
NotifyPropertyChanged("LastName");
}
}
public string Address
{
get { return this._address; }
set
{
this._address = value;
NotifyPropertyChanged("Address");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(string info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notifier
{
class Program
{
static void Main(string[] args)
{
Person sergio = new Person();
sergio.PropertyChanged += new PropertyChangedEventHandler(sergio_PropertyChanged);
sergio.Name = "Sergio";
Console.ReadLine();
sergio.Name = "Serg";
Console.ReadLine();
}
static void sergio_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
Console.WriteLine("Something changed!");
Console.WriteLine(e.PropertyName);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment