Windows Phone 8.1 How to programatically create a tile with specified template

608 views Asked by At

I'm trying to figure out how to create programatically a tile with specified template (TileSquare150x150Text03)? I tried to follow these guides link , MSDN and a few similiar, but wherever I paste < tile> ... < /tile > markup (e.g. in page or app .xaml file) Visual Studio underlines this markup and says that "tile is not supported in a Windows Phone project". I don't need any tile updates or tiles with two sides. Just simple one with specified template, background color/image and filled with my text.

Can someone explain me what I'm doing wrong? Thank you for your help.

1

There are 1 answers

0
rikkit On

Simple! You need to parse your tile template (an XML string) into an XElement object in code:

var template = "<tile>etc</tile>";
var tileXe = XElement.Parse(template);

Either configure the template xml to your liking before this or after (demo is in the article you linked)

then post it to the tile manager

var tileNotification = new TileNotification(tileXe);
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);

You can do this anywhere in your app as long as this code runs on the UI thread. Also note that there is a limit to how often you can update the tile, last time I checked it was every 15 seconds at most.