csharp mvvm add tag
FoggyFinder
Here is one of the common version of `ViewModelBase` class written in C#

```
public abstract class ViewModelBase : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
```

How to translate it to F#? Or, if it is impossible, what would be a good alternative?
Top Answer
FoggyFinder
Here's one way to achieve it:

```
open System.ComponentModel
open System.Runtime.CompilerServices
open System.Runtime.InteropServices

[<AbstractClass>]
type ViewModelBase() =
    let propertyChanged = 
        Event<PropertyChangedEventHandler, PropertyChangedEventArgs>()

    interface INotifyPropertyChanged with
        [<CLIEvent>]
        member this.PropertyChanged = propertyChanged.Publish

    member this.NotifyPropertyChanged([<CallerMemberName; Optional; DefaultParameterValue(null:string)>] propertyName) = 
        propertyChanged.Trigger(this, PropertyChangedEventArgs(propertyName))
```

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.