HelloWorld - WPF style!
Jun
30
Written by:
Tuesday, June 30, 2009 8:59 PM
Tonight I wanted to hit two birds with one stone! Read on for more details!
Unfortunately a week ago, my motherboard fried on me while downloading some code from CodePlex. The code from the study group MUST have been some HOT stuff to fry my motherboard like that! HAHA But that's no excuse for the lack of blogs, so here's one tonight.
A little while ago I said I was going to learn WPF but unfortunately I haven't had much of chance lately. Well, tonight I thought I would start reading my WPF book and try out an example or two. Here's what I came up with.

Nothing too grandious right? Well, from page 1 of the O'Reilly book, they said their code was "pretty much the smallest WPF "application" you can write in C#." Well, I found a way to compress it even more than they did.
using System;
using System.Windows;
class HelloWorldWPF
{
static void Main()
{
MessageBox.Show( "Hello World!" );
}
}
The second line is mandatory to make it a WPF app, that's the WPF objects namespace. The Main is of course standard to make your code run and then the MessageBox. I'm sure you could make your's smaller by declaring an int but then you wouldn't be "playing with WPF" would you? Well, ya, it could be argued I'm not playing with WPF neither BUT it is a window using the WPF namespace, so it COULD be argued. HAHA
Well, I'm off to try out my next example. I hope over the course of the summer to have more WPF/SL2 blogs. Keep posted!
PS Ya, I know I'm missing the [STAThread] attribute on the Main method, and that it's required, but for my "smallest app" test, it runs without it! So there, haha!
Source Code: http://www.pchenry.com:8080/svn/blog/trunk/2009/FirstWPFApp