WPF Running Code on Startup

WPF Post #1 from a complete WPF n00b.  Strange, I feel like a complete loser that has to start a WPF how-to blog post with a defensively-toned comment about how it seems that everyone but myself has mastered WPF by now, and I haven't even considered putting it into production here yet...  (Much of the stuff I am learning is buried inside various discussion forums, and in 2-year old blog posts by the early-adopters).  I'm not going to do that though.  Instead, I'll keep this post short & sweet for my own future reference, by jumping right into the steps and follow up with an in-context example of how it is being used in @shanselman's blockbuster WPF app, BabySmash.

Hooking up a WPF App's startup event handler in Visual Studio 2008:

New WPF Application Solution

Double-click on App.xaml in the Solution Explorer

The XML begins by declaring the Application element.  Add a new attribute inside, called 'Startup', and VS should prompt you for a "New Event Handler".  Hit enter, and the Application_Startup event handler is created in the codebehind.  Rt-click on the "Application_Startup" value, click "View Code" to jump to that method in your code.

In Context: Scott Hanselman's BabySmash (Download the Source)

In Scott Hanselman's BabySmash Application_Startup method, his BabySmash.Controller class was created and .Launch()ed.  Inside Controller.Launch():
- Initialize app Timer event handler(s)
- ClickOnce update-checking / update-complete handling
- Define the BabySmash window style & behavior, including mouse click & wheel event handlers.
- Load App Resources
- Handle command-line args
- Start app Timer

Print | posted on Friday, August 15, 2008 1:51 PM

Feedback

No comments posted yet.
Title  
Name
Email (never displayed)
Url
Comments   
Please add 2 and 1 and type the answer here: