Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace App.ViewModel
- {
- public class BaseViewModel : INotifyPropertyChanged
- {
- public BaseViewModel()
- {
- }
- #region INotifyPropertyChanged Members
- public event PropertyChangedEventHandler PropertyChanged;
- #endregion
- protected void OnPropertyChanged(string propertyName)
- {
- PropertyChangedEventHandler handler = this.PropertyChanged;
- if (handler != null)
- {
- handler(this, new PropertyChangedEventArgs(propertyName));
- }
- }
- }
- }
- //usage
- namespace App.ViewModel
- {
- public class Book : BaseViewModel
- {
- public Book()
- {
- }
- private string author;
- public string Author
- {
- get
- {
- return this.author;
- }
- set
- {
- if (this.author != value)
- {
- this.author = value;
- //No need to write property change events as its in base class
- this.OnPropertyChanged("Author");
- }
- }
- }
- private string title;
- public string Title
- {
- get
- {
- return this.title;
- }
- set
- {
- if (this.title != value)
- {
- this.title = value;
- this.OnPropertyChanged("Title");
- }
- }
- }
- private IEnumerable<Chapter> chapters;
- public IEnumerable<Chapter> Chapters
- {
- get
- {
- return this.chapters;
- }
- set
- {
- if (this.chapters != value)
- {
- this.chapters = value;
- this.OnPropertyChanged("Chapters");
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment