Creating a live tile for WP8 with a dynamic image from the control throws a "NotSupportedException"

I use the following code to take a user control, make a bitmap from it, and then save it in isolated storage for 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 } 

NotSupportedException gets the ShellTile.ActiveTiles.First().Update() method with very non descriptive messages.

Is there something that I'm obviously doing wrong?

+4
source share
2 answers

The “TargetInnvocationException” exception actually hid the main “NotSupportedException” exception problem that I found after moving ShellTile.ActiveTiles.First().Update() from the UI thread.

The exception was still not descriptive regarding the problem, but after some rooting through various forums and documentation, I found that the path to the dynamically created image is very important when using it with Live Tiles.

If you use an image in isolated storage for a live tile or shell, then the base folder should be

/ General / ShellContent

After change

 const string filename = "/LiveTiles/LiveTileRegular.jpg"; 

to

 const string filename = "/Shared/ShellContent/LiveTileRegular.jpg"; 

Everything worked fine.

Could we, the Windows Phone developers, get the best messaging for exceptions?!? :)

+11
source

I believe ShellTile.ActiveTiles . The first (orDefault) is the application tile, not the secondary pinned fragments. Try calling Update from the second tile forward using Skip (1).

0
source

All Articles