Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between raisepropertychanged and PropertyChanged?

Tags:

c#

mvvm

i think both are same,but i found use of them in only one file such as below code.here code for raisepropertychanged .

public decimal Amount
        {
            get
            {
                return _amount;
            }
            set
            {
                _amount = value;
                RaisePropertyChanged("Amount");
            }
        }

here code for PropertyChanged:

 public event PropertyChangedEventHandler PropertyChanged;

    private void RaisePropertyChanged(string propertyName)
    {
        // take a copy to prevent thread issues
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(propertyName));
        }
    }

plz explain difference between them:

like image 247
prjndhi Avatar asked May 20 '12 00:05

prjndhi


People also ask

What is RaisePropertyChanged?

The RaisePropertyChanging event is used to notify UI or bound elements that the data has changed. For example a TextBox needs to receive a notification when the underlying data changes, so that it can update the text you see in the UI.

What is RaisePropertyChanged WPF?

RaisePropertyChanged("User"); From MSDN: The PropertyChanged event can indicate all properties on the object have changed by using either null or String. Empty as the property name in the PropertyChangedEventArgs. (No need to refresh all the Properties in this case)

How to use 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.


1 Answers

PropertyChanged is an event. RaisePropertyChanged is the method used to raise the event.

Of course, you could invoke the event directly from your property setter, but then you would have to check every time if the handler is not null... better to do it in one place.

like image 117
Thomas Levesque Avatar answered Nov 16 '22 03:11

Thomas Levesque