1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
public class Person
{
public string Nom { get; set; }
public string Prenom { get; set; }
}
public class PersonViewModel : INotifyPropertyChanged
{
private const string NomPropertyName = "Nom";
private const string PrenomPropertyName = "Prenom";
private Person person;
public string Nom
{
get { return this.person.Nom; }
set
{
if (this.person.Nom == value) return;
this.person.Nom = value;
RaisePropertyChanged(NomPropertyName);
}
}
public string Prenom
{
get { return this.person.Prenom; }
set
{
if (this.person.Prenom == value) return;
this.person.Prenom = value;
RaisePropertyChanged(PrenomPropertyName);
}
}
public PersonViewModel(Person person)
{
if (this.person == null) throw new ArgumentNullException("person");
this.person = person;
}
#region INotifyPropertyChanged Membres
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
} |
Partager