2012-10-01 60 views
0

我正在寫一個Windows 8應用程序,並試圖讓活動的瓷磚正常工作。這裏是我到目前爲止(所有App.xaml.cs):Windows 8 Live Tile更新無法正常工作

OnLaunched()

Window.Current.VisibilityChanged += Current_VisibilityChanged; 

對於該事件處理程序:

void Current_VisibilityChanged(object sender, Windows.UI.Core.VisibilityChangedEventArgs e) 
{ 
    // create a string with the tile template xml 
    string tileXmlString = "<tile><visual><binding template=\"TileSquareBlock\">" + App.VM.GetImageLinks() + "</binding></visual></tile>"; 

    // create a DOM 
    Windows.Data.Xml.Dom.XmlDocument tileDOM = new Windows.Data.Xml.Dom.XmlDocument(); 
    // load the xml string into the DOM, catching any invalid xml characters 
    tileDOM.LoadXml(tileXmlString); 

    // create a tile notification 
    TileNotification tile = new TileNotification(tileDOM); 

    // send the notification to the app's application tile 
    TileUpdateManager.CreateTileUpdaterForApplication().Update(tile); 
} 

App.VM.GetImageLinks()回報:

<tile> 
    <visual> 
     <binding template=\"TileSquareBlock\"> 
      <image id=\"1\">Assets/Img1.jpg</image> 
      <image id=\"2\">Assets/Img2.jpg</image> 
      <image id=\"3\">Assets/Img3.jpg</image> 
     </binding> 
    </visual> 
</tile> 

在一分鐘,我基本上只是試圖讓這些圖像sh在開始屏幕上。我的猜測是VisibilityChanged是錯誤的事件,因爲它似乎太頻繁發生。

回答

4

正在使用的XML無效,因爲TileSquareBlock模板不包含任何圖像。請參閱tile template catalog以查看各種可視模板及其相應的XML。

NotificationsExtensions庫(在MSDN tiles sample中找到)提供了一個將圖像和文本字段映射到命名屬性的對象模型。它提供了更多驗證並可能簡化您的代碼。

+0

是的我想他想要tileSquareImage –