2012-10-01 59 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 –