Skip to content

Instantly share code, notes, and snippets.

@mbmccormick
Created November 30, 2012 16:35
Show Gist options
  • Save mbmccormick/4176835 to your computer and use it in GitHub Desktop.
Save mbmccormick/4176835 to your computer and use it in GitHub Desktop.
Updating a FlipTile through reflection in Windows Phone 7.1
public static void UpdateFlipTile(Uri tileId, string title, int count, string backTitle, string backContent, Uri smallBackgroundImage, Uri backgroundImage, Uri backBackgroundImage, Uri wideBackgroundImage, Uri wideBackBackgroundImage, string wideBackContent)
{
// 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 });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment