Skip to content

Instantly share code, notes, and snippets.

@mbmccormick
Created November 30, 2012 16:34
Show Gist options
  • Save mbmccormick/4176825 to your computer and use it in GitHub Desktop.
Save mbmccormick/4176825 to your computer and use it in GitHub Desktop.
Creating a FlipTile through reflection in Windows Phone 7.1
public static void CreateFlipTile(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 "Create" that takes the new Tile templates.
Type shellTileType = Type.GetType("Microsoft.Phone.Shell.ShellTile, Microsoft.Phone");
// Get the constructor for the new FlipTileData class and assign it to our variable to hold the Tile properties.
var CreateTileData = flipTileDataType.GetConstructor(new Type[] { }).Invoke(null);
// Set the properties.
SetProperty(CreateTileData, "Title", title);
SetProperty(CreateTileData, "Count", count);
SetProperty(CreateTileData, "BackTitle", backTitle);
SetProperty(CreateTileData, "BackContent", backContent);
SetProperty(CreateTileData, "SmallBackgroundImage", smallBackgroundImage);
SetProperty(CreateTileData, "BackgroundImage", backgroundImage);
SetProperty(CreateTileData, "BackBackgroundImage", backBackgroundImage);
SetProperty(CreateTileData, "WideBackgroundImage", wideBackgroundImage);
SetProperty(CreateTileData, "WideBackBackgroundImage", wideBackBackgroundImage);
SetProperty(CreateTileData, "WideBackContent", wideBackContent);
// Invoke the new version of ShellTile.Create.
shellTileType.GetMethod("Create", new Type[] { typeof(Uri), typeof(ShellTileData), typeof(bool) }).Invoke(null, new Object[] { tileId, CreateTileData, true });
}
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