it is with deepest sorrow that I'm posting to report Mark passed away on December 1, 2010. We tried to let all his friends and colleagues know, but no doubt there are people who knew and loved Mark, yet I didn't know or didn't know how to contact. If you are just hearing about Mark's death from this post, I am so very sorry. You can contact me at ali <dot> mischke <at> yahoo <dot> com.
Sending peace and love to all those who are grieving.
There are many good reasons to not use F# for your presentation layer, but doing so can be a great learning exercise. It's a bit cumbersome to set up, so I created a project template in order to simplify things.
When creating a WPF app in F# without this template, there are several hoops that you have to jump through:
Your new project gives you a nice, boring, empty form, but Visual Studio provides designer support when you open the XAML file. Event wire-up remains a manual process. Project templates can be created using File -> Export Template. A link to download the F# WPF Application template is at the end of this post.
Creating a new F# WPF Application project from the installed template gives you a Program.fs file:
open System open System.IO open System.Reflection open System.Windows open System.Windows.Controls open System.Windows.Markup open System.Xml let xamlFile = Assembly.GetExecutingAssembly().GetManifestResourceStream("MainWindow.xaml"); let createWindow (xamlFile : Stream) = using (XmlReader.Create(xamlFile)) (fun xaml -> XamlReader.Load(xaml) :?> Window) [<STAThread>] do createWindow(xamlFile) |> Application().Run |> ignore
and a MainWindow.xaml file:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainForm" Height="300" Width="300"> <Grid> </Grid> </Window>
The template works with both Visual Studio 2008 and 2010, although in 2010 it pops up the following message. I haven't yet figured out how to prevent this, but choosing the Reload option gets things back on track.
The template is installed by placing the .zip file in your My Documents\Visual Studio 20xy\Templates\Project Templates folder.