使用控件中的动态图像为 WP8 创建动态磁贴会引发"NotSupportedException"



我使用以下代码获取自定义用户控件,从中制作位图,然后将其保存到隔离的存储中,以用于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抛出到ShellTile.ActiveTiles.First().Update()方法上。

有什么我明显做错了吗?

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

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

如果您在独立存储中使用映像用于活动磁贴或shell磁贴,则基本文件夹必须为

/共享/ShellContent

改变后

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

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

一切正常

我们Windows Phone开发者能得到更好的异常消息吗?:)

我相信ShellTile.ActiveTiles.First(或default)是应用程序的平铺,而不是次要的固定平铺。尝试使用Skip(1)从第二个贴图开始调用Update。

最新更新