Search code examples
c#xmlwindows-8live-tile

Live Tile Update


I have a media application that needs to display the track image and title on a Live Tile. Right now I have the following code:-

private void SetLiveTile()
    {
        var LiveTile = @"<tile>
                            <visual version=""1"">
                              <binding template=""TileWideSmallImageAndText01"">
                                <text id=""1"">" + MediaControl.ArtistName + " - " + MediaControl.TrackName + @"</text>
                                <image id=""1"" src=" + MediaControl.AlbumArt + @"""/>
                              </binding>
                              <binding template=""TileSquarePeekImageAndText02"">
                                <text id=""1"">" + MediaControl.ArtistName + " - " + MediaControl.TrackName + @"</text>
                                <image id=""1"" src=" + MediaControl.AlbumArt + @"""/>
                              </binding>
                            </visual>
                          </tile>";

        XmlDocument tileXml = new XmlDocument();
        tileXml.LoadXml(LiveTile);

        var tileNotification = new Windows.UI.Notifications.TileNotification(tileXml);
        Windows.UI.Notifications.TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
    }

It currently doesn't work, the LoadXml fails with error code c00ce502.

I also need it to update every 1 minute at least, though it would be awesome if I could update it every 30 seconds. It also needs to remove the Live Tile and revert to the original tile upon the closing of the application.


Solution

  • For the XML issue it looks like you're missing the opening quote in the src tags, try

     <image id=""1"" src=""" + MediaControl.AlbumArt + @"""/>
    

    As for updating on a minute or 30-second basis, take a look at this sample on dev.windows.com.

    Clearing the tile on termination could be tricky since you're not informed programmatically of all cases where the app is indeed terminated.