Created
July 2, 2014 16:44
-
-
Save phillipsj/d28720411ee9320fdc2d to your computer and use it in GitHub Desktop.
INotifyPropertyChane without WPF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Child | |
{ | |
public string ParentPopertyName { get; set; } | |
} | |
public class Parent: INotifyPropertyChanged | |
{ | |
public Parent() | |
{ | |
this.PropertyChanged += Parent_PropertyChanged; | |
} | |
void Parent_PropertyChanged(object sender, PropertyChangedEventArgs e) | |
{ | |
this._myFavoriteChild.ParentPopertyName = e.PropertyName; | |
} | |
public event PropertyChangedEventHandler PropertyChanged; | |
// This method is called by the Set accessor of each property. | |
// The CallerMemberName attribute that is applied to the optional propertyName | |
// parameter causes the property name of the caller to be substituted as an argument. | |
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "") | |
{ | |
if (PropertyChanged != null) | |
{ | |
PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); | |
} | |
} | |
private Child _myFavoriteChild; | |
public Child MyFavoriteChild | |
{ | |
get { return _myFavoriteChild; } | |
set | |
{ | |
_myFavoriteChild = value; | |
NotifyPropertyChanged(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment