Nathan Nathan - 14 days ago 5
C# Question

Why Can i Not call OnPropertyChanged when using [ImplementPropertyChanged]

I am implementing a class using fody ImplementPropertyChanged:

[ImplementPropertyChanged]
public class Translator
{
public string this[string Text]
{
get
{
...
}
}

public void Invalidate()
{
OnPropertyChanged("item");
}
}


Visual Studio tells me, that OnPropertyChanged is not defined. I thought, that ImplementPropertyChanged would define it.

How can I manually trigger a property change? In this case the indexer property changed.

Answer

It does implement OnPropertyChanged during compile time, so it is not visible and available for you during development. If you like to trigger the property change manually, implement the interface by yourself or use a base class that implements it.