使用来自控件的动态图像为WP8创建实时磁贴会抛出"NotSupportedException"

Mik*_*rds 4 c# isolatedstorage dynamic-image-generation live-tile windows-phone-8

我正在使用以下代码来获取自定义用户控件,从中制作位图,然后将其保存到隔离存储中以用于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
}
Run Code Online (Sandbox Code Playgroud)

NotSupportedException被扔在ShellTile.ActiveTiles.First().Update()非常非描述性消息的方法.

有什么东西我显然做错了吗?

Mik*_*rds 11

"TargetInnvocationException"异常实际上隐藏了我在ShellTile.ActiveTiles.First().Update()移出UI线程后发现的"NotSupportedException"异常的根本问题.

这个例外仍然没有描述问题是什么,但经过不同的论坛和文档的翻版之后,我发现动态创建的图像的路径在与Live Tiles一起使用时非常重要.

如果您在隔离存储中使用图像以用于实时图块或外壳图块,则必须使用基本文件夹

/共享/ ShellContent

改变之后

const string filename = "/LiveTiles/LiveTileRegular.jpg";
Run Code Online (Sandbox Code Playgroud)

const string filename = "/Shared/ShellContent/LiveTileRegular.jpg";
Run Code Online (Sandbox Code Playgroud)

一切都很好.

我们的Windows Phone开发人员可以获得更好的异常消息吗?!?:)