NotifyPropertyChanged属性会产生编译器错误

时间:2016-04-17 19:18:07

标签: c# mvvm mvvm-light inotifypropertychanged postsharp

我将Postharp实现到我用MVVM-Light制作的现有项目中。我在viewmodel中定义了我的属性,如下所示:

public WindowState WindowState
{
    get
    {
        return windowState;
    }

    set
    {
        if(windowState != value)
        {
            windowState = value;
            RaisePropertyChanged("WindowState");
        }
    }
}

我实施了PostSharp的NotifyPropertyChanged属性:

[NotifyPropertyChanged]
public class MainViewModel : ViewModelBase
{
    public WindowState WindowState { get; private set; }
}

现在我在启动程序时遇到了这个编译错误:

Class ViewModels.MainViewModel implements INotifyPropertyChanged but does not define an OnPropertyChanged method with the following signature: void OnPropertyChanged(string propertyName)

我是否必须在我的viewmodel中实现这样的方法,甚至是覆盖ViewModelBase?

1 个答案:

答案 0 :(得分:0)

仅将属性[NotifyPropertyChanged]应用于班级ViewModelBase。它将通过继承进入后代类。