let createCommand action canExecute=

            let event1 = Event<_, _>()

            {

                new ICommand with

                    member this.CanExecute(obj) = canExecute(obj)

                    member this.Execute(obj) = action(obj)

                    member this.add_CanExecuteChanged(handler) = event1.Publish.AddHandler(handler)

                    member this.remove_CanExecuteChanged(handler) = event1.Publish.AddHandler(handler)

            }

 let myCommand = createCommand

                        (fun _ -> ())

                        (fun _ -> true)

 let ObjectExpression() =

    printfn "WPF command using object expression"

Last edited Feb 29, 2012 at 6:08 PM by ttliu2000, version 1

Comments

Thecentury Sep 19, 2012 at 12:04 PM 
Seems like you have used one AddHandler of two by mistake :)