Last active
December 11, 2015 18:28
-
-
Save blacktaxi/4641562 to your computer and use it in GitHub Desktop.
Base WPF ViewModel in F#
This file contains 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
type SomethingViewModel() as this = | |
inherit ViewModelBase() | |
let (<<+) (_ : unit) (e : Microsoft.FSharp.Quotations.Expr) = | |
this.OnPropertyChanged e | |
let mutable somePropertyValue = "" | |
member x.SomeProperty | |
with get() = somePropertyValue | |
and set value = (somePropertyValue <- value) <<+ <@ x.SomeProperty @> | |
This file contains 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
open System | |
open System.ComponentModel | |
open Microsoft.FSharp.Quotations | |
open Microsoft.FSharp.Quotations.Patterns | |
type ViewModelBase() = | |
let propertyChanged = new Event<_, _>() | |
interface INotifyPropertyChanged with | |
[<CLIEvent>] | |
member x.PropertyChanged = propertyChanged.Publish | |
abstract member OnPropertyChanged: string -> unit | |
default x.OnPropertyChanged(propertyName : string) = | |
propertyChanged.Trigger(x, new PropertyChangedEventArgs(propertyName)) | |
member x.OnPropertyChanged(expr : Expr) = | |
let propName = | |
match expr with | |
| PropertyGet(a, b, list) -> b.Name | |
| _ -> failwith "Not a valid property expression %A" expr | |
x.OnPropertyChanged(propName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment