Adding Windows Phone 8 and Windows Phone 7.8 Tile functionality to Windows Phone OS 7.1 apps

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Windows Phone 8 and Windows Phone 7.8 feature new Tile sizes that help light up the Start screen. If you plan to maintain an app that targets Windows Phone OS 7.1, you can use reflection to access Windows Phone 8 and Windows Phone 7.8 APIs that showcase the new Tile functionality. This way, if your Windows Phone OS 7.1 app runs on Windows Phone 8 or Windows Phone 7.8, those customers will have access to the new Tile features.

Requirements

The Windows Phone SDK Update for Windows Phone 7.8 provides updates for both Windows Phone SDK 8.0 and Windows Phone SDK 7.1 to let you see how your app looks and runs on a Windows Phone 7.8 device. To add wide tile support to your app, the only recommended and supported SDK to use is Windows Phone SDK 8.0.

Note

If you add wide tiles to your app in the Windows Phone SDK 7.1 tools, an error occurs when you build the app because of the new <AppExtra> element in the App manifest file for Windows Phone 8. To publish your app successfully to the Windows Phone Store, you can use the unsupported workaround described in Adding wide tiles to apps with the Windows Phone SDK 7.1.

Supported features

A Windows Phone OS 7.1 app that runs on Windows Phone 8 or Windows Phone 7.8 supports the following Tile features:

Creating and updating Windows Phone 8 and Windows Phone 7.8 Tiles in Windows Phone OS 7.1 apps

You create and update Windows Phone 8 and Windows Phone 7.8 Tiles in your Windows Phone OS 7.1 app in the same way as a Windows Phone 8 app. The one difference is that you must first update the small, medium, and (optionally) wide default Tile with a local image. On the next update, you can use a local or remote image as usual.

You must use reflection to enable Windows Phone 8 and Windows Phone 7.8 Tile functionality in Windows Phone OS 7.1 apps. For more information about reflection and how to use it, see Reflection in the .NET Framework.

Note

To enable the wide Tile or set the image on the small Tile, your app's default Tile has to be updated at run time using the ShellTile..::.Update method and the flip Tile template.

Updating the app manifest file

  1. In Solution Explorer, expand Properties, right-click WMAppManifest.xml, choose Open With, and then select Source Code (Text Editor) With Encoding.

  2. Add the following <AppExtra> element above the <App> element.

    <AppExtra  AppPlatformVersion="8.0">
        <Extra Name="Tiles"/>
    </AppExtra>
    

Note

AppPlatformVersion="8.0" applies to both Windows Phone 8 and Windows Phone 7.8.

Adding code to update a Windows Phone 8 or Windows Phone 7.8 Tile using reflection

Depending on the OS version, you add code to update the Windows Phone 8 or Windows Phone 7.8 Tile using reflection.

  1. At the class level, check the OS version. The following shows how to check for Windows Phone 7.8 or later:

    private static Version TargetedVersion = new Version(7, 10, 8858);
    public static bool IsTargetedVersion {get{return Environment.OSVersion.Version >= TargetedVersion;}}
    
  2. Use the above IsTargetedVersion variable to determine which Tile code you should use. This way, your app will work on Windows Phone OS 7.1, as well as, Windows Phone 8 and Windows Phone 7.8.

    The following code example shows methods that are used to update a flip Tile using reflection.

    public static void UpdateFlipTile(
                string title, 
                string backTitle, 
                string backContent, 
                string wideBackContent, 
                int count, 
                Uri tileId, 
                Uri smallBackgroundImage, 
                Uri backgroundImage, 
                Uri backBackgroundImage, 
                Uri wideBackgroundImage, 
                Uri wideBackBackgroundImage)
    {
       if (IsTargetedVersion)
       {
          // Get the new FlipTileData type.
          Type flipTileDataType = Type.GetType("Microsoft.Phone.Shell.FlipTileData, Microsoft.Phone");
    
          // Get the ShellTile type so we can call the new version of "Update" that takes the new Tile templates.
          Type shellTileType = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone");
    
          // Loop through any existing Tiles that are pinned to Start.
          foreach (var tileToUpdate in ShellTile.ActiveTiles)
          {
             // Look for a match based on the Tile's NavigationUri (tileId).
             if (tileToUpdate.NavigationUri.ToString() == tileId.ToString())
             {
                // Get the constructor for the new FlipTileData class and assign it to our variable to hold the Tile properties.
                var UpdateTileData = flipTileDataType.GetConstructor(new Type[] { }).Invoke(null);
    
                // Set the properties. 
                SetProperty(UpdateTileData, "Title", title);
                SetProperty(UpdateTileData, "Count", count);
                SetProperty(UpdateTileData, "BackTitle", backTitle);
                SetProperty(UpdateTileData, "BackContent", backContent);
                SetProperty(UpdateTileData, "SmallBackgroundImage", smallBackgroundImage);
                SetProperty(UpdateTileData, "BackgroundImage", backgroundImage);
                SetProperty(UpdateTileData, "BackBackgroundImage", backBackgroundImage);
                SetProperty(UpdateTileData, "WideBackgroundImage", wideBackgroundImage);
                SetProperty(UpdateTileData, "WideBackBackgroundImage", wideBackBackgroundImage);
                SetProperty(UpdateTileData, "WideBackContent", wideBackContent);
    
                // Invoke the new version of ShellTile.Update.
                shellTileType.GetMethod("Update").Invoke(tileToUpdate, new Object[] { UpdateTileData });
                break;
             }
          }
       }
    
    }
    
    private static void SetProperty(object instance, string name, object value)
    {
       var setMethod = instance.GetType().GetProperty(name).GetSetMethod();
       setMethod.Invoke(instance, new object[] { value });
    }
    

See Also

Other Resources

Tiles and notifications for Windows Phone 8

Now Available: Windows Phone SDK Update for 7.8

Windows Phone 7.8 and Windows Phone 8 Live Tile light up for Windows Phone OS 7.1 apps