Question

How do I change the background image of a live tile in my Windows 8 app to a local image? The XML for the template I am using is:

<tile>
  <visual>
    <binding template="TileWideImageAndText01">
      <image id="1" src="image1.png" alt="alt text"/>
      <text id="1">Text Field 1</text>
    </binding>  
  </visual>
</tile>

For the text, I use

        XmlDocument xmltile= Windows.UI.Notifications.TileUpdateManager.GetTemplateContent(Windows.UI.Notifications.TileTemplateType.TileWideImageAndText01);

        xmltile.GetElementsByTagName("text")[0].AppendChild(xmltile.CreateTextNode("73°F, Mostly Cloudy"));

        TileNotification tileupdate = new Windows.UI.Notifications.TileNotification(xmltile);

        Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().Update(tileupdate);

But what about for the image?

Was it helpful?

Solution

From here:

The following code uses a local image from the app's package. This type of image is included in your Visual Studio solution file and is packaged as part of your app. These images are accessed by using the "ms-appx:///" prefix. As a best practice, we also assign optional alt text for accessibility purposes such as screen readers.

XmlNodeList tileImageAttributes = tileXml.GetElementsByTagName("image");
((XmlElement)tileImageAttributes[0]).SetAttribute("src", "ms-appx:///images/redWide.png");
((XmlElement)tileImageAttributes[0]).SetAttribute("alt", "red graphic");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top