Friday, March 27, 2009

Hello, World in F# + WPF

Here’s the small version of F# + WPF Hello, world.  Note that there’s zero Xaml involved.

open System
open System.Windows
open System.Windows.Controls

type MainWindow(app: Application) as self =
  inherit Window()
    let button = Button(Content = "Bye")
    button.Click.Add(fun f -> app.Shutdown(0))
    self.Content <- button

type App() =
  inherit Application()
  static member Go() =
    let app = new App()
    app.Run(new MainWindow(app, Title = "Hello world")) 
    |> ignore

[<STAThread>] App.Go()

The references are very similar to the C# code:

No comments: