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

前端之家收集整理的这篇文章主要介绍了c# – 从一个实现INotifyPropertyChanged的基类继承?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这个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 ..

@R_404_323@

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

猜你在找的C#相关文章