Search
Thursday, December 13, 2018 ..:: Home ::.. Register  Login
   Calendar  
     
  
   Search  
     
  
   Blogroll  
     
  
   Disclosure  
All blog entries are the opinions of the author and do not necessarily reflect the opinions of their employer. All the code presented is for explanation and demonstration purposes only. Any damages incurred to your site and/or data are not the responsibility of the author. Every effort is taken to ensure the code properly compiles, however sometimes there are some hiccups and you might be required to do your own debugging.
     
  
   TechTidBits (Blog)  

HelloWorld - WPF style!

Jun 30

Written by:
Tuesday, June 30, 2009 8:59 PM  RssIcon

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.

Hello World

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

Tags:
Categories:
Location: Blogs Parent Separator TechTidBits

Your name:
Gravatar Preview
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment   Cancel 
     
  
Copyright 1999-2012 by PCHenry.com   Terms Of Use  Privacy Statement