IPropertyChanged Code Snippet

In .NET there is the INotifyPropertyChanged system to let the UI know that the data that it is bound to has changed. To take advantage of that you have to go ahead and type out the code for every property that you want to auto update the UI.... This is annoying so I have for a while been using a simple little snippet to easily produce my Properties on objects that impliment INotifyPropertyChanged. To use it you will hit CTRL+K + CTRL+X which is the default key combination to use for code snippets in Visual Studio. Then simply select the snippet you want ot use.

To install it on Windows 7 go to:

%HOMEPATH%\My Documents\Visual Studio 2010\Code Snippets\Visual C#\My Code Snippets\ and unzip the snippet file there.

You can see the snippet in action here http://www.youtube.com/watch?v=BaCSL77nIkI. This will generate properties like this:

private string firstName;
public string FirstName
{
	get { return this.firstName; }
	set
	{
		if (this.firstName != value)
		{
			this.firstName = value;
			this.OnPropertyChanged("FirstName");
		}
	}
}

*Update: Yes I know that it is INotifyPropertyChanged I am not going to change the title as it is already propagated with IPropertyChanged in the title.


Attachment: snippet.zip

Add a Comment

Be the first one to add a comment. Please Login or Register to add comment.