2
votes

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
Are you targeting Silverlight or RunTime? How have you tried to create the tile? You may take a look at this answer (WinRT).Romasz
Thank you for the answer! I'm targeting RunTime. This code works fine with me, but how can I set SecondaryTile one of built-in templates? With this solution I have only one line of text at the bottom of the tile, but I need to display at least 3 or 4 lines like in TileSquare150x150Text03 template.adam_z
I think you will need to send a notification to a tile, which uses templates you are talking about. Good reference is at MSDN.Romasz
I mentioned about this site in my first post. The problem is mainly with < tile> ... < /tile > tag. I can't add this markup to any .xaml file in my project without getting an error. I'm working on VSE 2013.adam_z
There are couple of ways you can obtain XmlDocument: 1. The easiest will be just to get a template: TileUpdateManager.GetTemplateContent(TileTemplateType.TileWide310x150ImageAndText01);. 2. Load from string var doc = new XmlDocument(); doc.LoadXml(string); You put your <tile>.. in string str = @"<tile>.... 3. You can also load document from file XmlDocument.LoadFromFileAsync() - for this add xml file in your project.Romasz

1 Answers

-1
votes

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.