In the previous blog:Lab: Move an object using Silverlight and XNA in Windows Phone Part 1
We generated all of the XNA code, less a few important lines of code. In this blog let’s take a look at the XAML and related code behind.
Ok let’s take a look at the XAML code:
First off you add a Grid, which is like a spreadsheet, then you define the Row Heights for 3 rows. Then you place a stack panel in Grid Row 2, which is the third row since the row count starts with zero. Then you add an Image from the toolbox, using the Properties you set up a “source” for the image and then you use the Events tab to generate a tap event for the image, this way you will simply tap the screen to change to the image. The Tap event will be in the code behind.
The properties box for any control can be brought up by clicking the control one time and then pressing F4. At the top of the Properties there are two “tabs” that say Properties (Hand holding a deed, representing a property, get it?) and then on the right hand side says Events (lightning bolt). Generally speaking the Properties tab looks busy and the Events tab has only one or two things filled in. To automatically create an event in the code behind, simply double click the event and that will create the correct event in the code behind.
Now we need to add the components to implement the UIElementRenderer in the code behind:
In the class scope add the UIElementRenderer variable
In the Class constructor add an eventHandler:
Now add a method that you use for the eventhandler, do this after any of the methods in the class:
In the OnDraw event add the UIRenderer code, this is part of the spriteBatch process and must be placed between the spriteBatch.Begin and the spriteBatch.End. In this case order is not important, often it is, but not this time.
And that should do it!