Skip to content

Instantly share code, notes, and snippets.

@toburger
Created June 7, 2013 09:25
Show Gist options
  • Save toburger/5728124 to your computer and use it in GitHub Desktop.
Save toburger/5728124 to your computer and use it in GitHub Desktop.
Extension method to allow the use of Quotation Expressions for NotifyPropertyChanged
[<AutoOpen>]
module PropertyChangedBaseEx
open Caliburn.Micro
open System
open System.Linq.Expressions
open Microsoft.FSharp.Linq.QuotationEvaluation
open Microsoft.FSharp.Quotations
type PropertyChangedBase with
member self.NotifyOfPropertyChange (expr: Expr<'a>) =
let body = expr.ToLinqExpression()
let func = Expression.Lambda<Func<'a>>(body)
self.NotifyOfPropertyChange func
@toburger
Copy link
Author

toburger commented Jun 7, 2013

usage example:

[<Export(typeof<IShell>)>]
type ShellViewModel [<ImportingConstructor>] (testViewModel: TestViewModel) =
    inherit Screen()

    let mutable isBusy = false

    interface IShell

    member self.IsBusy
        with get() = isBusy
        and set(value) =
            isBusy <- value
            self.NotifyOfPropertyChange <@ self.IsBusy @>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment