I have this BaseClass:
public class BaseViewModel : INotifyPropertyChanged
{
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
and a other class:
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 is here ( 2Times ), red underlined, it says:
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')
What I'm doing wrong? I only swept the PropertyChangedEvent to a new class: BaseViewModel..
You cannot raise the event outside the class it is declared in, use the method in the base class to raise it (make OnPropertyChanged
protected
).
Change derived class as follow:
public class SchemaDifferenceViewModel : BaseViewModel
{
private string firstSchemaToCompare;
public string FirstSchemaToCompare
{
get { return firstSchemaToCompare; }
set
{
firstSchemaToCompare = value;
OnPropertyChanged("FirstSchemaToCompare");
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With