Well the Ace WhipperSnapper, Kenny Spade, send me an email with an attachment that contained a simple example of how to do tombstoning with XNA Phone. Wow! I am so impressed, I am going to carefully share (or steal) his excellent code. After a screen sharing session using Lync, which is totally cool IM product, he knocked out the code in about 1 minute, I would take all day. Well that is the way it goes, I can still beat the heck out of him on building FORTRAN programs…. Maybe not. (Note: Ace WhipperSnapper is my phrase, and not approved by Kenny Spade.)
As payment, I will ask that you go to his excellent blog (it is much better than mine, he takes his time and does a great job of writing): http://blogs.msdn.com/kennyspade.
Ok, how did he do it? His approach required the use of EventArgs to add events to the XNA Game class, these additional events are related to the Phone Execution.
In a previous blog about working with the Silverlight and the App.XAML.cs, here we saw that XAML had a number of events of interest, so does XNA.
Let’s take a look carefully at Events, EventHandlers and EventArgs
What is an Event?
An event is a member that enables a class or object to provide notifications. Reference: C# Language Specifications, 220.127.116.11. Events
The event model in the .NET Framework is based on having an event delegate that connects an event with its handler. To raise an event, two elements are needed:
- A delegate that identifies the method that provides the response to the event.
- A class that holds the event data.
In the code the event is written:
- void yourPhoneApplication_Launching(object sender, LaunchingEventArgs e)
What is an EventHandler?
Represents the method that will handle an event that has no event data. (http://msdn.microsoft.com/en-us/library/system.eventhandler.aspx)
Clients react to events through event handlers. Event handlers are attached using the += operator and removed using the -= operator. Reference: C# Language Specifications, 18.104.22.168.
An example of EventHandler code can be found at: EventHandler(Of TEventArgs) Delegate
In the sample code, the EventHandler is shown in the following (I modified the Event Handler code in an attempt for clarification):
yourPhoneApplication.Launching += new EventHandler<LaunchingEventArgs>(yourPhoneApplication_Launching); yourPhoneApplication.Activated += new EventHandler<ActivatedEventArgs>(yourPhoneApplication_Activated); yourPhoneApplication.Deactivated += new EventHandler<DeactivatedEventArgs>(yourPhoneApplication_Deactivated); yourPhoneApplication.Closing += new EventHandler<ClosingEventArgs>(yourPhoneApplication_Closing);
What is an EventArgs?
EventArgs is the base class for classes containing event data. Reference: http://msdn.microsoft.com/en-us/library/system.eventargs.aspx
Note: The sample code is overly complex in the article.
Kenny didn’t make up the EventArgs in the EventHandler code these EventArgs are part of the using Microsoft.Phone; statement. The related EventArgs will show up in the IntelliSense as shown.
How to add an EventArgs
The code is on Kenny Spade’s site: http://blogs.msdn.com/kennyspade.
If you like his stuff leave a comment on HIS Blog. If you don’t like anything, feel free to leave it here.
If you are a student in my CSUDH class, this is one of the Blogs you are suppose to read. Code: #111AAA