I'm using the following code to take a custom user control, make a bitmap out of it, and then save it to isolated storage for the purposes of a WP8 Live Tile.
public static void UpdateTile()
{
var frontTile = new LiveTileRegular(); // Custom Control
frontTile.Measure(new Size(173, 173));
frontTile.Arrange(new Rect(0, 0, 173, 173));
var bmp = new WriteableBitmap(173, 173);
bmp.Render(frontTile, null);
bmp.Invalidate();
const string filename = "/LiveTiles/LiveTileRegular.jpg";
using (var isf = IsolatedStorageFile.GetUserStoreForApplication())
{
if (!isf.DirectoryExists("/LiveTiles"))
{
isf.CreateDirectory("/LiveTiles");
}
using (var stream = isf.OpenFile(filename, FileMode.OpenOrCreate))
{
bmp.SaveJpeg(stream, 173, 173, 0, 100);
}
Debug.WriteLine("Image Exists: " + (isf.FileExists(filename) ? "Yes" : "No")); // Displays "Yes"
}
ShellTile.ActiveTiles.First().Update(new FlipTileData
{
Title = "Title",
BackgroundImage = new Uri("isostore:" + filename, UriKind.Absolute),
}); // Throws a NotSupportedException
}
The NotSupportedException
gets thrown on the ShellTile.ActiveTiles.First().Update()
method with very non-descriptive messaging.
Is there something that I'm obviously doing wrong?