Search code examples
windows-8microsoft-metrowindows-runtimelive-tile

Windows 8 Live Tile Update not working


I'm writing a Windows 8 app and am trying to get live tiles working. Here's what I have so far (all in App.xaml.cs):

In OnLaunched():

Window.Current.VisibilityChanged += Current_VisibilityChanged;

The event handler for that:

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() returns:

<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>

At the minute, I'm basically trying to just get these images to show on the start screen. My guess is that VisibilityChanged is the wrong event, because it seems to occur too often.


Solution

  • The XML being used is invalid, as the TileSquareBlock template doesn't contain any images. See the tile template catalog to see the various visual templates and their corresponding XML.

    The NotificationsExtensions library (found in the MSDN tiles sample) provides an object model that maps the image and text fields to named properties. It provides more validation and may simplify your code.