Windows 8.1 Universal Apps (Part 2: Not Perfect)

Minor Problems

I said earlier that code can be shared between Universal Apps. This is true, but there are a few exceptions. For the most part, you can think of WinPRT as a subset of WinRT. There are several methods that WinRT has that will throw a NotImplementedException if you call them from WinPRT.

Mostly, these are thrown if you call methods that are not appropriate for using on a phone, such as trying to view the file system. However, there are some occasions where this can crop up when you’re doing something that might seem appropriate. The prime example of this is with Live Tiles.

Live Tiles

Both Windows 8.1 and Windows 8 have live tiles, and in Universal Apps you create them in the same way. However, Windows 8.1 supports live tile sizes that Windows Phone 8.1 does not. There’s a full description of all of the live tiles available on MSDN at The tile template catalog (Windows Runtime apps).

Obviously, the solution to this is that you’ll want your code to skip generating those live tiles on the phone.

Luckily, we can do this fairly easily with compile-time constants. When your Universal App project is compiled for the Windows Phone app, a constant WINDOWS_PHONE_APP is created. We can just check for this in our code to skip over live tile generation, like this:

var tileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150Text04);

var tileTextAttributes = tileXml.GetElementsByTagName("text");
tileTextAttributes[0].InnerText = text;

var squareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare150x150Text04);

var squareTileTextAttributes = squareTileXml.GetElementsByTagName("text");

var node = tileXml.ImportNode(squareTileXml.GetElementsByTagName("binding").Item(0), true);

var bigSquareTileXml = TileUpdateManager.GetTemplateContent(TileTemplateType.TileSquare310x310TextList02);

var bigSquareTileTextAttributes = bigSquareTileXml.GetElementsByTagName("text");

node = tileXml.ImportNode(bigSquareTileXml.GetElementsByTagName("binding").Item(0), true);

var tileNotification = new TileNotification(tileXml);