Search code examples
windows-8microsoft-metrolive-tile

Show a generated image on Live Tile


I create a custom image in my app (by capturing ink data for example) and then want to show the generated image on Live Tile. How can I do this?


Solution

  • all you need to do is assign the image to the live tile template.

    TileUpdateManager.GetTemplateContent(TileTemplateType.TileWideImageAndText01);
    
    XmlNodeList tileTextAttributes = tileXml.GetElementsByTagName("text");
    tileTextAttributes[0].InnerText = "Hello World! My very own tile notification";
    
    XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image");
    ((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-appx:///images/redWide.png");
    ((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic");
    
    XmlDocument squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareText04);
    XmlNodeList squareTileTextAttributes = squareTileXml.GetElementsByTagName("text");
    squareTileTextAttributes[0].AppendChild(squareTileXml.CreateTextNode("Hello World! My very own tile notification"));
    IXmlNode node = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true);
    tileXml.GetElementsByTagName("visual").Item(0).AppendChild(node);
    
    TileNotification tileNotification = new TileNotification(tileXml);
    
    tileNotification.ExpirationTime = DateTimeOffset.UtcNow.AddSeconds(10);
    
    TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);