4

我正在使用以下代碼來獲取自定義用戶控件,將其創建爲位圖,然後將其保存到獨立存儲以實現此目的的WP8 Live Tile。使用動態圖像爲控件創建動態圖像的動態拼貼會拋出「NotSupportedException」

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()方法具有非常非描述性消息。

有什麼我明顯做錯了嗎?

回答

11

「TargetInnvocationException」異常實際上隱藏了在將ShellTile.ActiveTiles.First().Update()移出UI線程之後發現的「NotSupportedException」異常的基礎問題。

這個例外對於什麼問題仍然沒有描述,但在翻閱了不同的論壇和文檔後,我發現動態創建的圖像在Live Tiles中使用時非常重要。

如果使用的圖像中的獨立存儲爲活瓷磚或殼瓦片的目的,則基本文件夾必須是

/共享/ ShellContent

改變

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

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

一切正常。

我們的Windows Phone開發人員能否獲得更好的異常消息? :)

+1

你是一個救星!正在摸索着我的頭! – soutarm 2013-07-13 03:57:10

0

我相信ShellTile.ActiveTiles。首先(或默認)是應用程序圖塊,而不是二級鎖定圖塊。嘗試使用跳過(1)從第二個磁貼開始調用更新。

+0

我實際上試圖使用圖像的應用程序瓷磚:) – 2013-03-22 21:54:54