gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 21:18:58 33 4
gpt4 key购买 nike

我有这个基类:

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 在这里 ( 2Times ),红色下划线,它说:

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 protected).

关于c# - 从一个实现 INotifyPropertyChanged 的​​基类继承?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9077106/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com