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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
| private string _Nom;
public string Nom
{
get { return _Nom; }
set
{
_Nom = value;
if (IsStringNullOrEmpty(value))
throw new ApplicationException("Le nom est un champ obligatoire.");
this.NotifyPropertyChanged("Nom");
}
}
private string _Prenom;
public string Prenom
{
get { return _Prenom; }
set
{
_Prenom = value;
if (IsStringNullOrEmpty(value))
throw new ApplicationException("Le prénom est un champ obligatoire.");
this.NotifyPropertyChanged("Prenom");
}
}
private string _Ville;
public string Ville
{
get { return _Ville; }
set
{
_Ville = value;
this.NotifyPropertyChanged("Ville");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged(String propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (null != handler)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
private ICommand _SaveCommand;
public ICommand SaveCommand
{
get
{
if (_SaveCommand == null)
_SaveCommand = new RelayCommand(SaveCommandExecute, SaveCommandCanExecute);
return _SaveCommand;
}
}
private void SaveCommandExecute(object parameter)
{
//Enregistrement des données
MessageBox.Show("Personne sauvegardée");
}
private bool SaveCommandCanExecute(object parameter)
{
return !IsStringNullOrEmpty(this.Nom) && !IsStringNullOrEmpty(this.Prenom);
}
private bool IsStringNullOrEmpty(string sValue)
{
return sValue == null || string.IsNullOrEmpty(sValue.Trim());
} |
Partager