raisepropertychanged 和 PropertyChanged 有什么区别? [英] what is the difference between raisepropertychanged and PropertyChanged?

查看:56
本文介绍了raisepropertychanged 和 PropertyChanged 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为两者都是一样的,但我发现它们只在一个文件中使用,例如下面的代码.这里是 raisepropertychanged 的​​代码.

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");
            }
        }

这里是 PropertyChanged 的​​代码:

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:

推荐答案

PropertyChanged 是一个事件.RaisePropertyChanged 是用于引发事件的方法.

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.

这篇关于raisepropertychanged 和 PropertyChanged 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆