csharp mvvm add tag
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
Here's one way to achieve it:

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

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

    interface INotifyPropertyChanged with
        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.