Frage

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?

War es hilfreich?

Lösung

The "TargetInnvocationException" exception was actually hiding the underlying problem of a "NotSupportedException" exception which I found after moving ShellTile.ActiveTiles.First().Update() out of the UI thread.

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

If you are using an image in isolated storage for the purpose of the live tile or shell tile, then the base folder must be

/Shared/ShellContent

After changing

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

to

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

Everything worked fine.

Could us Windows Phone developers get better exception messaging?!? :)

Andere Tipps

I believe ShellTile.ActiveTiles.First(orDefault) is the application tile, not secondary pinned tiles. Try calling Update from the second tile onwards using Skip(1).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top