Last active
August 27, 2018 18:17
-
-
Save willsam100/8efbae58ebf7f0c3ef843ae30a2144ff to your computer and use it in GitHub Desktop.
F# ViewModel Base
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace YourNamespaceHere | |
open System | |
open System.Collections.ObjectModel | |
open System.ComponentModel | |
open Microsoft.FSharp.Quotations | |
open Microsoft.FSharp.Quotations.Patterns | |
type ViewModelBase() = | |
let propertyChanged = new Event<_, _>() | |
let toPropName(query : Expr) = | |
match query with | |
| PropertyGet(a, b, list) -> | |
b.Name | |
| _ -> "" | |
interface INotifyPropertyChanged with | |
[<CLIEvent>] | |
member this.PropertyChanged = propertyChanged.Publish | |
abstract member OnPropertyChanged: string -> unit | |
default this.OnPropertyChanged(propertyName : string) = | |
propertyChanged.Trigger(this, new PropertyChangedEventArgs(propertyName)) | |
member this.OnPropertyChanged(expr : Expr) = | |
let propName = toPropName(expr) | |
this.OnPropertyChanged(propName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment