Search code examples
c#windows-8notificationswindows-store-appslive-tile

Live Tile not working due to error in setting image?


The App.xaml.cs page of my app contains the following method.

public static void SendLiveTileUpdate(Record rr)
{
    string imageUristring = "ms-appdata:///local/" + rr.Id.ToString() + ".jpg";

    XmlDocument wideTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideImageAndText01);

    XmlNodeList wideTileTextAttrib = wideTileXml.GetElementsByTagName("text");
    wideTileTextAttrib[0].InnerText = rr.Name;

    XmlNodeList wideTileImageAttrib = wideTileXml.GetElementsByTagName("image");

    //((XmlElement)wideTileImageAttrib[0]).SetAttribute("src", "ms-appdata:///local/" + rr.Id.ToString() + ".jpg");
    ((XmlElement)wideTileImageAttrib[0]).SetAttribute("src", imageUristring);
    ((XmlElement)wideTileImageAttrib[0]).SetAttribute("alt", "Image");

    //Wide tile Layout done

    XmlDocument sqTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareImage);

    XmlNodeList sqTileImageAttrib = sqTileXml.GetElementsByTagName("image");
    ((XmlElement)sqTileImageAttrib[0]).SetAttribute("src", imageUristring);
    ((XmlElement)sqTileImageAttrib[0]).SetAttribute("alt", "Image");

    IXmlNode node = wideTileXml.ImportNode(sqTileXml.GetElementsByTagName("binding").Item(0), true);
    wideTileXml.GetElementsByTagName("visual").Item(0).AppendChild(node);

    //Square tile set and added to wide tile xml

    TileNotification tileNot = new TileNotification(wideTileXml);

    tileNot.ExpirationTime = DateTime.Now.AddDays(5);

    updater.Update(tileNot);
}

On the page there is also the global variable updater, which is used on page initialization to call EnableNotificationQueue(true) (then later to update the queue as shown).

The problem is that when this code is run it doesn't work. I have deduced that it is something to do with the images because when the image assignments are excluded the live tile updates with the value of rr.Id.ToString(), but included the tile is never updated. this images referenced by imageUristring are present in the apps local storage (and the name corresponds with the Id of the method parameter), yet it still does not work. The images in question are under 200KB, and are 1920x1080. (I think that they will be scaled to fit the tile?)

What am I doing wrong? How could I get the tile to update with the image stored in the local storage?


Solution

  • Your images must be <= 1024x1024. From http://msdn.microsoft.com/en-us/library/windows/apps/Hh781198.aspx:

    Tile images must have dimensions less than or equal to 1024x1024 pixels, have a file size of less than or equal to 200 KB, and be of type .png, .jpg, .jpeg, or .gif.