Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

How to: Implement Property Change Notification

To support OneWay or TwoWay binding to enable your binding target properties to automatically reflect the dynamic changes of the binding source (for example, to have the preview pane updated automatically when the user edits a form), your class needs to provide the proper property changed notifications. This example shows how to create a class that implements INotifyPropertyChanged.

To implement INotifyPropertyChanged you need to declare the PropertyChanged event and create the OnPropertyChanged method. Then for each property you want change notifications for, you call OnPropertyChanged whenever the property is updated.

using System.ComponentModel;

namespace SDKSample
  // This class implements INotifyPropertyChanged 
  // to support one-way and two-way bindings 
  // (such that the UI element updates when the source 
  // has been changed dynamically) 
  public class Person : INotifyPropertyChanged
      private string name;
      // Declare the event 
      public event PropertyChangedEventHandler PropertyChanged;

      public Person()

      public Person(string value)
          this.name = value;

      public string PersonName
          get { return name; }
              name = value;
              // Call OnPropertyChanged whenever the property is updated

      // Create the OnPropertyChanged method to raise the event 
      protected void OnPropertyChanged(string name)
          PropertyChangedEventHandler handler = PropertyChanged;
          if (handler != null)
              handler(this, new PropertyChangedEventArgs(name));

To see an example of how the Person class can be used to support TwoWay binding, see How to: Control When the TextBox Text Updates the Source.

For the complete sample, see Simple Binding Sample.

Community Additions

© 2015 Microsoft