Geeks With Blogs
Freestyle Coding Programming in the Real World

When Microsoft announced that Windows Phone 7.5 would support applications that contained both Silverlight and XNA, I was really excited. However, after I played with it, I ran into one little annoyance. You are forced into a non-XNA enabled page by default1.

After some experimentation, I found a way to make lemonade. I used the ease of Silverlight animation to create my Splash Screen page. After the animation completes, it passes control to the actual XNA-enabled PhoneApplicationPage. However, this leaves the Splash Screen in the Back Stack.

The uninitiated may be wondering about this Back Stack. Windows Phone keeps a stack of all the pages it's loaded. This way, if something like a phone call interrupts, you can get back to where you were2. When you leave the Splash Screen, it is left on the Back Stack. This means that pressing the back button on the phone will take you back to the Splash Screen.

Getting rid of this can be a little phishy3. The application does expose a portion of the back stack into an object off the Page called the NavigationService. This version of the NavigationService keeps track of the changes within the app4. This lets us drop our entry, if it exists

In order to exploit this, we just need to add a simple little check in our OnNavigatedTo override:

protected override void OnNavigatedTo( NavigationEventArgs e ) {
if( this.NavigationService.CanGoBack ) {
JournalEntry _LastPage = this.NavigationService.RemoveBackEntry();

// Set the sharing mode of the graphics device to turn on XNA rendering
SharedGraphicsDeviceManager.Current.GraphicsDevice.SetSharingMode( true );

// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch( SharedGraphicsDeviceManager.Current.GraphicsDevice );

// TODO: use this.content to load your game content here

// Start the timer

base.OnNavigatedTo( e );

Now, of course, this is the simplistic version. If you're supporting multiple pages, you'll have to make sure you're being intelligent about dropping items. However, as usual, here is enough to get you started.

1Ok, so you CAN turn that default page into an XNA-enabled page. That's not the point; perhaps next week’s update.
2Think of navigation buttons on a web browser. Same type of Stack5.
3Pun intended.
4A say this version because WPF have an much nicer version.
5Ok, so there is a way to go up and down it, so it's not a true "stack." Let's not devolve into a theoretical CompSci discussion.

Posted on Friday, July 1, 2011 8:26 PM XNA , Windows Phone , Mango | Back to top

Comments on this post: Using the Default Silverlight Page in a Window Phone Rich Graphics Application

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Chris Gardner | Powered by: