Now that Windows Phone 8 is released the first thing you want to do as an app developer is update your app to Windows Phone 8, right? Wrong. My recommendation is to only update to your application to Windows Phone 8 if you need to take advantage of Windows Phone 8 features. Some of these you can do without upgrading the application at all.
Microsoft will automatically make those applications that are compatible with Windows Phone 8 available for those devices and Windows Phone 7.1 devices without making any changes at all. Space Weather got the nod to run on Windows Phone 8 even though I never updated the application at all, and that’s OK. That’s what I wanted. You see, if you upgrade your app to Windows Phone 8 SDK, you have to start maintaining 2 versions of the application where if you keep it on the 7.1 SDK and use reflection to get some Windows Phone 8 features you can maintain only 1. The only thing I wanted from Windows Phone 8 (for now) was the double-wide tile. Here’s how you can take a 7.1 application and use reflection to get 8.0 tiles and only support 1 version of the app.
Get the tools
Open your project
Once you have all the tools installed, open your project and build and test. Most likely it will without any issues. If not, use the Tim Gunn approach and “Make it work!” Be sure not to upgrade the project to 8.0. You can check the target phone version checking the properties of the project. The target version should be Windows Phone OS 7.1.
Save, backup, check-in, commit – whatever you need to do to get back to a working state.
Update the app manifest file
Open your app manifest file (in the properties folder in the solution explorer). Right click and choose ‘Open With…’ > Source Code (Text) Editor with Encoding. Now add the <AppExtra> element above the <App> element.
<a href="http://www.techtronic.us/technology/use-reflection-to-take-advantage-of-windows-phone-8-tiles-on-windows-phone-7/attachment/appextra-2/" rel="attachment wp-att-1051"><img class="wp-image-1051 aligncenter" title="appextra" src="http://www.techtronic.us/wp-content/uploads/2012/11/appextra1.png" alt="" width="599" height="90" /></a>
Add reflection code to update a Windows Phone 8 tile
If you already have code to update a Windows Phone 7 tile (which you should) all you have to do is add a check for the OS version and run the tile update based on the targeted OS version.
You will want to check the version at the class level:
Now you can use the IsTargetedVersion to decide which version of the Tile code you should run.
Here is the code that checks for the version and runs the Windows Phone 8 tile code:
Here is the code to update Windows Phone 7.1 tiles:
Build & Deploy
Now if you build and deploy to the different emulators, you will see that you have access to the new tile size on Windows Phone 8
..and your old code to update the live tile on Windows Phone 7 still works.
Be sure to update this code wherever you have it running. I actually had to update it in 2 places, once in my background task project that runs the code on a schedule, and once in main where it refreshes the tile when you launch the application.
(PS Sorry about screenshots to code, I’ll be updating my blog shortly so I can get properly formatted code inserts)