Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. using System.ComponentModel;
  2.  
  3. public class PersonaINotify : INotifyPropertyChanged
  4. {
  5. //Propiedades
  6. //En caso de que se cambie el valor, se debe llamar al método que lanza el evento PropertyChanged
  7. private string _nombre;
  8. public string Nombre
  9. {
  10. get { return this._nombre; }
  11. set
  12. {
  13. if (this._nombre != value)
  14. {
  15. this._nombre = value;
  16. this.NotifyPropertyChanged("Nombre");
  17. }
  18. }
  19. }
  20.  
  21. private int _edad;
  22. public int Edad
  23. {
  24. get { return this._edad; }
  25. set
  26. {
  27. if (this._edad != value)
  28. {
  29. this._edad = value;
  30. this.NotifyPropertyChanged("Edad");
  31. }
  32. }
  33. }
  34.  
  35. //Constructores
  36. public PersonaINotify()
  37. {
  38. Nombre = "";
  39. Edad = 0;
  40. }
  41. public PersonaINotify(string nombre, int edad)
  42. {
  43. Nombre = nombre;
  44. Edad = edad;
  45. }
  46.  
  47. //Implementación de la interfaz INotifyPropertyChanged
  48. public event PropertyChangedEventHandler PropertyChanged;
  49.  
  50. public void NotifyPropertyChanged(string propertyName)
  51. {
  52. this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement