Home > Metro, Windows 8 > Windows 8 Tile Notifications

Windows 8 Tile Notifications

Windows 8 enables to display app specific data without starting the app.

This mechanism can be used in many different ways.

Using Windows Notification Service

One way is to use the Windows Notification Service, which pushes updates to the tile. This requires, that the device is connected to the internet and that there is a app specific server side logic running, which acts as the source for the update.

Windows Notification Service then will act as a gateway and forward this messages to the device and its app tile.

I plan to describe the needed steps in a later post. First let’s see, how we can update the tile from with in the app itself.

 

Using local TileUpdateManager, during app runtime

An app can push data to the tile, whenever its running.

For this, the following code is needed:

  1. Fetch one of the predefined templates as XML:
    XmlDocument xmlDoc = 
    TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquareBlock); // using TileTemplateType.TileSquareBlock will return the following xml: //<tile> // <visual> // <binding template="TileSquareText01"> // <text id="1"></text> // <text id="2"></text> // </binding> // </visual> //</tile>

     

  2. Update the tile data

    var
    text1Node = xmlDoc.SelectSingleNode("//text[@id='1']");

    var
    newText1 = xmlDoc.CreateTextNode(headerText);

    text1Node.AppendChild(newText1);
    var text2Node = xmlDoc.SelectSingleNode("//text[@id='2']");
    var newText2 = xmlDoc.CreateTextNode(DateTime.Now.ToString("HH:mm:ss")
    +
    ": " + detailText);
    text2Node.AppendChild(newText2);

  3. Get a TileUpdater and perform the update

    TileNotification tileNotification = new TileNotification(xmlDoc);
    TileUpdater tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
    tileUpdater.Update(tileNotification);

Now the tile update should be visible within seconds…

 

 

 

Manually removing custom tile data

All updates to a tile stay visible until another update overwrites them. To reset the tile to the initial state, a call to Clear() will help:

TileUpdateManager.CreateTileUpdaterForApplication().Clear();

 

 

 

Using expiration to revert to the initial tile data


tileNotification.ExpirationTime =
new DateTimeOffset(DateTime.Now.AddSeconds(10));

 

 

Create Queue of Updates

 

Up to 5 tile notifications can be scheduled and the system will automatically rotate between this notifications. If more notifications will be added, then only the last 5 updates will be visible. Older notifications will be discarded.

 

To enable this queue behavior, the following code is needed:

TileUpdateManager.CreateTileUpdaterForApplication()
.EnableNotificationQueue(
true);

// Get a TileUpdater and perform the update

TileUpdater tileUpdater =
TileUpdateManager.CreateTileUpdaterForApplication();
for (int i = 0; i < 5; i++)
{
TileNotification tileNotification
= GetTileData(
"H"+ (i+1),"Scheduled: "
+ (i+1)); tileUpdater.Update(tileNotification);
}
  

Categories: Metro, Windows 8
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: