Post view page

Post #26

INotifyPropertyChanged
2012-01-30 08:55:16

 Whenever I create a new class that will be view in WPF and have the values change in the background I add the following.

The INotifyPropertyChanged give a hook for the WPF to pull on which then then link to the PropertyChanged event handle.

Each property then has to have a changed event sent to it, an empty property name will notify WPF that all properties have changed.

public class DataLink : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    private void SendPropertyChanged(String propertyName)
    {
        if ((this.PropertyChanged != null))
        {
            this.PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }

    private string _Field1;
    public string Field1
    {
        get { return this._Field1; }
        set { this._Field1 = value; this.SendPropertyChanged("Field1"); }
    }
}

Test right content

first test

Test right content

second test

Test right content

third test

this is a test