c# – 从一个实现INotifyPropertyChanged的基类继承?

c# – 从一个实现INotifyPropertyChanged的基类继承?,第1张

概述我有这个BaseClass: public class BaseViewModel : INotifyPropertyChanged{ protected void OnPropertyChanged(string propertyName) { if (PropertyChanged != null) { Property 我有这个BaseClass:
public class Baseviewmodel : INotifyPropertyChanged{    protected voID OnPropertyChanged(string propertyname)    {        if (PropertyChanged != null)        {            PropertyChanged(this,new PropertyChangedEventArgs(propertyname));        }    }    public event PropertyChangedEventHandler PropertyChanged;}

和另一个类:

public class SchemaDifferenceviewmodel : Baseviewmodel{    private string firstSchemaToCompare;    public string FirstSchemaToCompare    {        get { return firstSchemaToCompare; }        set        {            firstSchemaToCompare = value;            if (PropertyChanged != null)            {                PropertyChanged(this,new PropertyChangedEventArgs("FirstSchemaToCompare"));                //StartCommand.RaiseCanExecuteChanged();            }        }    }

PropertyChanged在这里(2次),红色下划线,它说:

Error   1   The event Baseviewmodel.PropertyChanged' can only appear on the left hand sIDe of += or -= (except when used from within the type 'SchemaDifferenceFinder.viewmodel.Baseviewmodel')

我做错了什么?我只将PropertyChangedEvent扫描到一个新类:Baseviewmodel ..

解决方法 您不能在声明它的类之外引发事件,使用基类中的方法来引发它(使OnPropertyChanged受保护). 总结

以上是内存溢出为你收集整理的c# – 从一个实现INotifyPropertyChanged的基类继承?全部内容,希望文章能够帮你解决c# – 从一个实现INotifyPropertyChanged的基类继承?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/1262979.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-06-08
下一篇2022-06-08

发表评论

登录后才能评论

评论列表(0条)

    保存