propnot – Code Snippet for Property with PropertyChanged event
propnot – Code Snippet for Property with PropertyChanged event
Using Silverlight 2 data binding, If we want the UI to be notified and updated with changes in the model, we have to implement System.ComponentModel.INotifyPropertyChanged interface:
public interface INotifyPropertyChanged
{
event PropertyChangedEventHandler PropertyChanged;
}
A property that wants to notify the program that its values was changed should raise the PropertyChanged event and provide the name of the property. For example:
public class Person : INotifyPropertyChanged
{
private string name;
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(Name));
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
In case you like to code fast as I like, and you use code snippets to speed things up, you can use propnot – code snippet with PropertyChanged event implementation like the sample above.
To use the snippet:
- Download this zip file.
- Extract the propnot.snippet file to your custom code snippets directory (C:\Users\guyb\Documents\Visual Studio 2008\Code Snippets\Visual C#\My Code Snippets).
- Use it in Visual Studio!
Enjoy!