HOW RAISE AN EVENT WHENEVER A PROPERTY'S VALUE CHANGED?

Manoj Bhatt

Total Post:154

Points:1086
Posted by  Manoj Bhatt
C#  .NET 
C#
 557  View(s)
Ratings:
Rate this:
I want to use an event whenever a property's value changed . how to use this in a program please help me.
  1. Anupam Mishra

    Post:135

    Points:949
    Re: How raise an event whenever a property's value changed?

    In C#, the INotifyPropertyChanged interface is used notify clients, typically binding clients, that a property value has changed.

    For example, consider an Employee class object with a property called FirstName. To provide property-change notification, the Employee class type implements the INotifyPropertyChanged interface and raises a PropertyChanged event when FirstName is changed.

    For change notification to occur in a binding between a bound client and a data source, your bound type should either:

    ·         Implement the INotifyPropertyChanged interface (preferred).

    ·         Provide a change event for each property of the bound type.

    Do not do both.

    For example, in below we have defined a property ‘FirstName

    private string _firstName;
            public string FirstName
            {
                get
                {
                    return _firstName;
                }
                set
                {
                    _firstName = value;
                    OnPropertyChanged("FirstName");
                }
            }

    Now, we have implementing the INotifyPropertyChanged interface

     

    public event PropertyChangedEventHandler PropertyChanged;
     
            protected void OnPropertyChanged(string propertyName)
            {
                OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
            }
     
     // occurring event        private void OnPropertyChanged(PropertyChangedEventArgs e)
            {
                         MessageBox.Show(“Changed in First Name ”+FirstName);
            }

    Output:


    I think in above example you are understand about raises event when 'FirstName'  property values are changed.

        For more details , you click here

      Modified On Jan-04-2016 05:37:49 AM
  1. Manoj Bhatt

    Post:154

    Points:1086
    Re: How raise an event whenever a property's value changed?

    thank you sir.

  1. Anupam Mishra

    Post:135

    Points:949
    Re: How raise an event whenever a property's value changed?

    For more details you can also read out this one: Click Here

      Modified On Jan-06-2016 12:03:30 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!