One way to ease writing PropertyChanged events

Here’s a quick tip for those who want to write propertychanged events but dislike frameworks;

public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] String propertyName = "")
{
  if (PropertyChanged != null)
  {
    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  }
}

Example;

Guid currentProfileId;
public Guid CurrentProfileId
{
  get
  {
    return this.currentProfileId;
  }
  set
  {
    if (this.currentProfileId != value)
    {
      this.currentProfileId = value;
      NotifyPropertyChanged();
    }
  }
}

Advertisements
This entry was posted in Silverlight, Windows 8, Windows Phone and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s