strangelights.com

Main F# Site

Edit Edit
Print Print
Recent Changes Recent Changes
Subscriptions Subscriptions
Lost and Found Lost and Found
Find References Find References
Rename Rename
Search
List all versions List all versions
Avalon Hello World
.
Summary

This is from a Web log post; see http://dcooney.com/archive/2005/03/19/806.aspx for more information.

 (* lets us conveniently construct colours from RGB triples *)
 let color r g b =
      System.Windows.Media.Color.FromRgb(Byte.of_int r, Byte.of_int g, Byte.of_int b)


 (* a couple of colours *)
 let red = color 204 0 0
 let black = color 0 0 0


 (* Avalon application's OnStartingUp event builds its main
   window *)
 let on_starting_up (event_args: System.Windows.StartingUpCancelEventArgs) =
      (* create a window *)
      let win = new System.Windows.Window() in
      win.Text <- "Hello, Avalon-F# World!";


      (* create a label *)
      let text = new System.Windows.Controls.TextBlock() in
      text.TextContent <- "Hello,\nAvalon-F# world!";
      text.FontFamily <- "Lucida Sans";
      text.FontSize <- System.Windows.FontSize.FromInches(0.8);
      text.TextAlignment <- System.Windows.TextAlignment.Center;
      text.VerticalAlignment <- System.Windows.VerticalAlignment.Center;


      (* this is Avalon, so need to do something vaguely pretty;
         here I'm adding a cool gradient to the label's text *)
      let brush = new System.Windows.Media.LinearGradientBrush() in
      brush.StartPoint <- new System.Windows.Point(0.0, 0.0);
      brush.EndPoint <- new System.Windows.Point(0.0, 1.0);
      brush.AddStop(red, 0.0);
      brush.AddStop(black, 1.0);
      text.Foreground <- (brush :> System.Windows.Media.Brush);


      (* add the label to the window *)
      win.Content <- (text :> obj);


      (* show the main window *)
      win.Show()


 let _ =
      (* create and run Avalon application *)
      let app =
            { new System.Windows.Application() as base with
              OnStartingUp(event_args) =
                  base.OnStartingUp(event_args);
                  on_starting_up event_args } in
      app.Run()
Welcome to F Sharp Wiki, view the HomePage

This site supports the new NoFollow anti-spam initiative.

Recent Topics

Copyright 2005, Robert Pickering (Others where credited) | Terms of Use