Windows 8 Live Tiles and NotificationsExtensions

One of the ways to make your Windows 8 Store App stand out from the crowd is to include a Live Tile. There are different ways to get a tile to update but the easiest is to create a local update of your tile. A local update happens when your app changes the tile while it is running.

There are plenty of blog posts that show the basics of creating and using a live tile like Ged Mead’s blog on adding a live tile (http://vbcity.com/blogs/xtab/archive/2013/01/13/windows-store-apps-adding-a-live-tile.aspx).

But I found that working with the XML can get tedious at times. Turns out Microsoft thought the same thing and created a wrapper for doing live tile work without having to play with XML. The library is called NotificationsExtensions.WinRT and is published through NuGet. After getting the package add an Imports NotificationsExtensions.TileContent to your code.

The nicest thing about it in my mind is that you can treat the tiles like normal objects with properties and methods. So instead of creating a tile using the TileUpdateManager.GetTemplateContent you use the TileContentFactory. This doesn’t seem like such a big deal, but the resulting object is no longer an XmlDocument but an object with properties like Image or textBody1 that can be set.

So as an example, lets take the TileSquareBlock tile template and see how it changes the code. (a complete example is in Ged’s blog post referenced above).

Dim tileXml = TileUpdateManager.GetTemplateContent _
(TileTemplateType.TileSquareBlock)

Would look like this.

Dim tileXml1 = TileContentFactory.CreateTileSquareBlock()

Not that big of a change. Now if we want to set the text for the first text tag we would have to find the tag, then add text to it like this.

Dim textElements = tileXml.GetElementsByTagName("text") 
Dim tileText1 = textElements(0)
tileText1.AppendChild(tileXml.CreateTextNode("10"))

But using NotificationsExtenstions the same code would look like this.

tileXml1.TextBlock.Text = "10"

Clearly this is easier to read and understand. This really shines when it comes to adding images. For example, if we were working with the TileSquarePeekImageAndText01 template and wanted to add an image to the tile all we would have to do is this.

tileXml2.Image.Src = "ms-appx:///images/image1.jpg"

The only other code you have to change is when you are creating the notifications. Instead of this.

Dim notification = New TileNotification(tileXml)

It would look like this.

Dim notification1 = tileXml1.CreateNotification()

I’m not sure why this isn’t built into the SDK for the store apps but it isn’t. But with NuGet it is easy to add and certainly worth the few minutes it takes.

The extensions also have code in it to handle badges and toast content.

About these ads

2 Responses to Windows 8 Live Tiles and NotificationsExtensions

  1. Thanks for this article!

  2. Windows 8 PRO is one of the best OS i ever seen, i think 9 will be also amazing. Thanks for post!

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 111 other followers

%d bloggers like this: