Guest User

Untitled

a guest
Aug 14th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. namespace App.ViewModel
  2. {
  3. public class BaseViewModel : INotifyPropertyChanged
  4. {
  5. public BaseViewModel()
  6. {
  7. }
  8.  
  9. #region INotifyPropertyChanged Members
  10.  
  11. public event PropertyChangedEventHandler PropertyChanged;
  12.  
  13. #endregion
  14.  
  15. protected void OnPropertyChanged(string propertyName)
  16. {
  17. PropertyChangedEventHandler handler = this.PropertyChanged;
  18. if (handler != null)
  19. {
  20. handler(this, new PropertyChangedEventArgs(propertyName));
  21. }
  22.  
  23. }
  24. }
  25. }
  26.  
  27. //usage
  28. namespace App.ViewModel
  29. {
  30. public class Book : BaseViewModel
  31. {
  32.  
  33. public Book()
  34. {
  35. }
  36.  
  37. private string author;
  38. public string Author
  39. {
  40. get
  41. {
  42. return this.author;
  43. }
  44. set
  45. {
  46. if (this.author != value)
  47. {
  48. this.author = value;
  49. //No need to write property change events as its in base class
  50. this.OnPropertyChanged("Author");
  51. }
  52. }
  53. }
  54.  
  55. private string title;
  56. public string Title
  57. {
  58. get
  59. {
  60. return this.title;
  61. }
  62. set
  63. {
  64. if (this.title != value)
  65. {
  66. this.title = value;
  67. this.OnPropertyChanged("Title");
  68. }
  69. }
  70. }
  71.  
  72. private IEnumerable<Chapter> chapters;
  73. public IEnumerable<Chapter> Chapters
  74. {
  75. get
  76. {
  77. return this.chapters;
  78. }
  79. set
  80. {
  81. if (this.chapters != value)
  82. {
  83. this.chapters = value;
  84. this.OnPropertyChanged("Chapters");
  85. }
  86. }
  87. }
  88.  
  89. }
  90.  
  91. }
Add Comment
Please, Sign In to add comment