Thursday, February 1, 2007

My first simple .NET Framwork 3.0 app

My friends and I had just submitted the project proposals for Imagine Cup 2007: Software Design (You can find more info about Imagine Cup at One of the requirements of the project, only for the first round here in Thailand, is to build the application on the .NET Framework 3.0 which means it's time to start learning WPF, WCF, WF now!

To get started, make sure you have Visual Studio 2005 and these extensions.

First, I created a new project of type Windows Application under .NET Framework 3.0 category. I named it "HelloWPF".

I then designed the form. The Visual Studio's WPF designer is seperated into 2 panes : one for the visual designer and the other for editing raw XAML code. You can click on the "swap" button to swap the XAML pane and visual designer pane too. However, this CTP version of designer is hard to use and is not very impressive.

After that, I tried to add an event handler to the click event of the button. But there is no same old "Events" tab in the property window. Double clicked the button in the designer also not work. It takes me some time to figured out that I has to map event to code in XAML or to map it in the code under the constructor. I choose the latter way. Here is my C# code.

public partial class Window1 : System.Windows.Window

public Window1()
btnSayHello.Click +=
new RoutedEventHandler(btnSayHello_Click);

void btnSayHello_Click(object sender,
RoutedEventArgs e)
txtMessage.Text = "WPF : สวัสดี ว่าไง";


I could finally press the F5 button and this is the result.