Thursday, March 26, 2009

Starting out with WPF in F# – but first, C#

I've started to use F# with WPF, and thought that the best way of going about it would be to start with just bare code for the most stripped-down C# app that would do anything.

Most of the WPF examples out there start with too much Xaml - seems like it's just going to get in the way for now.

Norbert Eder's blog had the meat of this - I just stripped it down even more.

using System;
using System.Windows;
using System.Windows.Controls;

public class App : Application
static void Main(string[] args)
Application app = new Application();
app.Run(new MainWindow());

public class MainWindow : Window
public MainWindow()
Button button1 = new Button();
button1.Content = "Bye";
button1.Click += new RoutedEventHandler(button1_Click);
this.Content = button1;
this.Title = "Hello world";

void button1_Click(object sender, RoutedEventArgs e)

The project only needs a couple references – PresentationCore, PresentationFramework, System, and WindowsBase:



No comments: