Home
Insert
Update snippet 'WPF Command in F#'
Title
Passcode
Description
demonstrate how to use object expression to create a WPF/Silverlight command.
Source code
open System.Windows.Input 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)
Tags
wpf
silverlight
wpf
silverlight
Author
Link
Reference NuGet packages
If your snippet has external dependencies, enter the names of NuGet packages to reference, separated by a comma (
#r
directives are not required).
Update