Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Windows Phone 8 Tile functionality to Windows Phone OS 7.1 app

I'm trying to support the new Windows Phone tile functionality in my existing Windows Phone OS 7.1 application, using the documentation from MSDN. However, I can't seem to create an IconicTile through reflection as it keeps giving me NullReferenceExceptions and AmbiguousMatchExceptions. Here is the code I am using:

public static void CreateIconicTile(Uri tileId, string title, int count, string wideContent1, string wideContent2, string wideContent3, Uri smallIconImage, Uri iconImage, Color backgroundColor)
{
    // Get the new IconicTileData type.
    Type iconicTileDataType = Type.GetType("Microsoft.Phone.Shell.IconicTileData, 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");

    // Get the constructor for the new IconicTileData class and assign it to our variable to hold the Tile properties.
    StandardTileData CreateTileData = new StandardTileData();

    // Set the properties.
    SetProperty(CreateTileData, "Count", count);
    SetProperty(CreateTileData, "WideContent1", wideContent1);
    SetProperty(CreateTileData, "WideContent2", wideContent2);
    SetProperty(CreateTileData, "WideContent3", wideContent3);
    SetProperty(CreateTileData, "SmallIconImage", smallIconImage);
    SetProperty(CreateTileData, "IconImage", iconImage);
    SetProperty(CreateTileData, "BackgroundColor", backgroundColor);

    // Invoke the new version of ShellTile.Create.
    shellTileType.GetMethod("Create").Invoke(null, new Object[] { tileId, CreateTileData });
}

I also tried creating the tile using the Windows Phone OS 7.1 way (ShellTile.Create(...)) and then calling the UpdateIconicTile method via reflection as described in the MSDN documentation. But that didn't work either.

Any help would be greatly appreciated. Thanks!

EDIT: Just to clarify, I am checking the platform version to ensure this code only runs on Windows Phone 8 devices and I have added the necessary code to my manifest.

RESOLVED: Thanks to the answer given by Martin Suchan below, I was able to solve this problem. The problem was with my call to Invoke(...) missing some properties. Here is the new line I am using to actually create the tile:

shellTileType.GetMethod("Create", new Type[] { typeof(Uri), typeof(ShellTileData), typeof(bool) }).Invoke(null, new Object[] { tileId, CreateTileData, true });
like image 235
Matt McCormick Avatar asked Dec 02 '25 15:12

Matt McCormick


1 Answers

Have you tried the library Mangopollo, that contains working wrapper for creation new tiles in WP7.1 apps when running on WP8?
http://mangopollo.codeplex.com/

like image 193
Martin Suchan Avatar answered Dec 04 '25 12:12

Martin Suchan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!