Creating WPF Commands in F#

Another quick post to demonstrate how to create WPF Command classes in F#. Notably, these include a CLR event in the inherited interface that needs to be implemented in F#.

Example:

#light

open Microsoft.FSharp.Control
open System.Windows.Input

type MyCustomCommand() =

  // This is the member field for the event
  let CanExecuteChangedEvent = new Event<_,_>()

  interface ICommand with
    member self.Execute (argument:obj) = ()
    member self.CanExecute (argument:obj) = true
    [<CLIEvent>]
    member self.CanExecuteChanged = 
        CanExecuteChangedEvent.Publish

The F# source code for Event is good educational reading for the curious!

Reference material:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s