Rotating Live Tiles to keep interest

LiveTiles_thumb7_thumb1If you are developing an application or game  for Windows 8, making sure you have an engaging, inviting, or informative live tile is an absolute must.  I am always surprised when I see the amount of effort a developer puts into their application, but then neglects to spend any time on their live tile.  A live tile is a unique way to engage the consumer while they are not using your application.  It is not only a way to entertain, but done right, it will drive them back into your application or game time and time again.  In this series, we will discuss the many aspects of Live Tiles, from what should be placed on your live tile, to utilizing Azure and Push Notifications to send data to your application.

  1. Creating A Live Tile that is Engaging and Inviting
  2. Working with Live Tiles Locally
  3. Rotating Live Tiles to keep interest (This Post)
  4. Modifying Live Tiles in a Background Process
  5. Using Azure and Push Notifications with Live Tiles

Change the Scenery

In addition to inviting them into your application, you want to make sure that the information on your live tile does not become static. While it may engage them once, fresh content is important to keep them engaged.  You can rotate up to 5 different tiles at a time. To begin, we will use the project we created in the last post (if you don’t have that, you can create a new project and follow along)

This time we will be adding the code that goes behind the Rotate Tiles button.

image

Double click on the Rotate Tiles button to get to the button click handler. Add the following code inside the click handler.

AddTileNotification("Title 1", "This is the message for number 1","1");AddTileNotification("Title 2", "This is the message for number 2", "2");AddTileNotification("Title 3", "This is the message for number 3", "3");AddTileNotification("Title 4", "This is the message for number 4", "4");AddTileNotification("Title 5", "This is the message for number 5", "5");

 

For now, you will get an error stating that AddTileNotification does not exist.  We will add that shortly.  First add the following declaration to the top of your class.

TileUpdater tileUpdater;

 

Now in the constructor add the following code

tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();tileUpdater.EnableNotificationQueue(true);

 

This will new up an instance of the TileUpdateManager and will enable notification queuing.

Now lets add the AddTileNotification method.

private void AddTileNotification(string title, string message, string tag){    var templateType = TileTemplateType.TileWideSmallImageAndText04;    var xml = TileUpdateManager.GetTemplateContent(templateType);

    var textNodes = xml.GetElementsByTagName("text");    textNodes[0].AppendChild(xml.CreateTextNode(title));    textNodes[1].AppendChild(xml.CreateTextNode(message));

    //IMPORTANT if the image is not found, this update will fail SILENTLY    var imageNodes = xml.GetElementsByTagName("image");    var elt = (XmlElement)imageNodes[0];    elt.SetAttribute("src", "ms-appx:///Assets/SmallLogo.png");

    var tile = new TileNotification(xml);    tile.Tag = tag;    tileUpdater.Update(tile);

}

 

Since we already covered most of this code in the previous post (http://thesociablegeek.com/windows-8/livetiles/working-with-live-tiles-locally/) we will just discuss what is different

DON’T PAST THIS CODE.. IT IS ALL ABOVE, THIS IS JUST FOR DISCUSSION

If  we look at the method signature we can see that we are taking in a title, message, and a tag,

private void AddTileNotification(string title, string message, string tag)

 

The title and message will be used to hydrate the xml we are using for the tile (again see last post for more detail).  Since you are only able to rotate 5 tiles at any given time, the tag property allows us to have a reference to the tile we want to replace.  If you don’t use the tag property, it will replace the first tile that was added (FIFO). You can see where we apply the tag here

tile.Tag = tag;

 

If you run the project and click the Rotate Tiles button, you can see that it will rotate through all of the tiles we created. If you want to replace a tile, add another button to the form and add the following to its button click handler.

AddTileNotification("Title 6", "This is the message for number 6", "2");
This will replace the second tile (tagged as 2) with this tile.
That’s all there is to it, there is of course added complexity if you want to create different types of tiles (which you can). You would just need to modify your method to take into account the different Tile Types and adjust the needed data accordingly.
In the next post, we we look at how you can do all of this from a background process so that changes can be made while the user is not using the program.
Happy Programming,
Daniel Egan – The Sociable Geek


33 Responses to Rotating Live Tiles to keep interest
  1. bekPVoOehtTJcdX
    December 7, 2012 | 9:43 pm

    YSFZGeWBQRaQJyZPLn 7971

  2. Noah Vanderjagt
    December 8, 2012 | 7:14 pm

    Those cupcakes seem fantastic, would just really like just one with my cup of tea, I will just really need to settle for my Kitkat

  3. Refugio Calemine
    December 9, 2012 | 10:00 am

    So EXCACTLY what did the Rock N’ Roll Hall of Fame say?

  4. Eldon Waltemath
    December 9, 2012 | 10:59 pm

    Wedding Dresses 2012|Wedding Dress| Wholesale Wedding Dresses…

  5. Derick Haubrich
    December 10, 2012 | 12:23 am

    It is really a shame you do not have a donate button! I’d most absolutely donate to this fantastic weblog! I suppose for now i’ll settle for bookmarking and incorporating your RSS feed to my Google account. I glance forward to new updates and can talk concerning this web page with my Facebook group. Talk shortly!

  6. Jeffrey Sinkey
    December 10, 2012 | 10:47 pm

    Thank you for every other wonderful article. The place else may just anyone get that kind of info in such a perfect means of writing? I’ve a presentation subsequent week, and I am at the search for such information.

  7. Xerox Tonery
    December 11, 2012 | 3:48 am

    obviously like your web-site but you have to check the spelling on several of your posts. Many of them are rife with spelling issues and I to find it very troublesome to inform the reality however I’ll definitely come again again.

  8. Ganzen Artikel lesen
    December 11, 2012 | 5:51 am

    I love your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to create my own blog and would like to know where u got this from. appreciate it

  9. bedrooms designs
    December 11, 2012 | 7:23 am

    Your weblog is very educational, keep up the good writing!!!!

  10. ephedrine
    December 11, 2012 | 8:22 am

    Mr/Ms NG, you probably did not name any movie designed by, when you say persons in pakistan, who have produced any movie the place Hindu or Christian gods are insulted.. Kindly examine prior to you pen down everything and do not mold the facts. The fact is the fact that a Muslim will under no circumstances denounce any other prophets, be it Christians or Jews etc..

  11. link
    December 11, 2012 | 9:37 am

    Do you mind if I quote a few of your posts as long as I provide credit and sources back to your weblog? My blog is in the exact same area of interest as yours and my visitors would certainly benefit from some of the information you present here. Please let me know if this alright with you. Thank you!

  12. singapore seo company
    December 11, 2012 | 10:01 am

    Some will do it on the market aware of niche service offering may require other search marketing and online advertising. A robot.txt file may result in making your website receives a “credit” for those keywords. Each time a visitor clicks on that link, your website URL or page URL, within links, within your main headings or other key headings, within your content. {||||

  13. Sandy Cazeault
    December 11, 2012 | 10:12 am

    Thank you repeatedly for the article post.Bless you Again. Really Great.

  14. Jilly
    December 11, 2012 | 5:32 pm

    Advantageous Information About Cheap Framed Art Prints And Their Benefits To Community

  15. the best background check
    December 11, 2012 | 5:51 pm

    Real nice design and superb content material , practically nothing else we want : D.

  16. more helpful hints
    December 11, 2012 | 8:39 pm

    Please let me know if you’re looking for a writer for your blog. You have some really good posts and I feel I would be a good asset. If you ever want to take some of the load off, I’d really like to write some articles for your blog in exchange for a link back to mine. Please blast me an e-mail if interested. Thank you!

  17. a fantastic read
    December 11, 2012 | 9:57 pm

    Rather entertaining many thanks, I believe your visitors could possibly want significantly more posts similar to this carry on the very good work.

  18. ebikes
    December 11, 2012 | 10:28 pm

    These are only few of the electric engine! And in some cities, may be more numerous than human-powered bicycles.

  19. Maryalice Worman
    December 12, 2012 | 3:19 am

    I’ve been surfing online greater than three hours these days, yet I by no means found any fascinating article like yours. It is lovely worth enough for me. In my opinion, if all webmasters and bloggers made just right content as you did, the net can be much more helpful than ever before.

  20. promotional code for amazon september 2012
    December 12, 2012 | 8:25 am

    Wow that was strange. I just wrote an really long comment but after I clicked submit my comment didn’t show up. Grrrr… well I’m not writing all that over again. Anyway, just wanted to say fantastic blog!

  21. related web site
    December 12, 2012 | 8:45 am

    Graphics are truly fastidious source of lessons instead of wording, its my knowledge, what would you say?

  22. read more here
    December 12, 2012 | 8:52 am

    Hey just wanted to give you a brief heads up and let you know a few of the images aren’t loading properly. I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers and both show the same results.

  23. turbo timer
    December 12, 2012 | 9:36 am

    We are a bunch of volunteers and opening a new scheme in our community. Your web site offered us with useful information to work on. You’ve performed a formidable task and our whole group can be thankful to you.

  24. termites treatment
    December 12, 2012 | 11:02 am

    Pretty component of content. I just stumbled upon your website and in accession capital to say that I get actually loved account your weblog posts. Any way I’ll be subscribing in your augment and even I success you access persistently rapidly.

  25. Free Chat Line
    December 12, 2012 | 1:00 pm

    Simply desire to say your article is as amazing. The clearness in your post is simply cool and i can assume you are an expert on this subject. Well with your permission let me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please keep up the enjoyable work.

  26. just click the following article
    December 12, 2012 | 1:07 pm

    For most up-to-date news you have to visit world-wide-web and on the web I found this web site as a finest website for most recent updates.

  27. Wilhelmina Gaetano
    December 12, 2012 | 1:35 pm

    I think other web site proprietors should take this site as an model, very clean and great user genial style and design, let alone the content. You’re an expert in this topic!

  28. background criminal check
    December 12, 2012 | 7:02 pm

    I went over this internet site and I conceive you have a lot of fantastic information, saved to fav (:.

  29. job search
    December 12, 2012 | 7:34 pm

    The ideal manager will participate in the process of staff in the organization. Quantity pertains to the candidate’s personality. According to WCBS, last year the NYPD hired 2,983 but lost 3,290 officers to retirements, resignations, and attrition. Applicants also consider whether or not they are appropriate for an interview.

  30. link
    December 12, 2012 | 7:38 pm

    Real instructive and wonderful structure of subject material, now that’s user pleasant (:.

  31. echelon @ alexandra
    December 12, 2012 | 11:14 pm

    Median COO’s brought home $4.6-7.6 million. Home builders and developers will need homes maintained, especially with winterization in the event of a covered peril. For example, some companies won’t cover it.

  32. http://youtube.com/watch?v=xbL01vfSggg
    January 7, 2013 | 4:37 am

    I have not checked in here for some time since I thought it was getting boring, but the last several posts are really great quality so I guess I’ll add you back to my daily bloglist. You deserve it my friend. :)

  33. visit this site
    February 7, 2013 | 1:18 pm

    Excellent post, thanks for the good read. You really helped me comprehend this subject much better.