Use reflection to take advantage of Windows Phone 8 tiles on Windows Phone 7

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

Of course you will need the newer tools.  Get Visual Studio 2012.  Get the Windows Phone SDK 8.0.  Install and update if needed.

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

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.

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)

7 thoughts on “Use reflection to take advantage of Windows Phone 8 tiles on Windows Phone 7

  1. great post from you but i have a little bug with it. today the WP 7.8 SDK came out and Microsoft says like you i should add the APPExtraa element but if i add it i get this error : 

    “Warning 1 The element ‘Deployment’ in namespace ‘http://schemas.microsoft.com/windowsphone/2009/deployment’ has invalid child element ‘AppExtra’. List of possible elements expected: ‘App’.”

    any help with this?

    1. See this post.  It should solve your problems.  http://www.techtronic.us/technology/windows-phone-7-8-sdk-one-tile-code-base-to-rule-them-all/

      1. thx for the new post you have made 🙂 i will try out now and will report if it solve the issue, but i must say in front i haven’t changed the development appplatformversion never. and it stays on 7.1 and my app works without problems…

  2. hi,
    anybody solved this error in wp7.5 for using wp8 tiles..?
    The element “Deployment” in namespace “http://schemas.microsoft.com/windowsphone/2009/deployment” has invalid child element “AppExtra”. List of possible elements expected: “App”.

Leave a Reply

Your email address will not be published. Required fields are marked *