(X) Hide this
    • Login
    • Join
      • Say No Bots Generate New Image
        By clicking 'Register' you accept the terms of use .

Windows Phone 7.5 - Using advanced tiles API

(3 votes)
Andrea Boschin
>
Andrea Boschin
Joined Nov 17, 2009
Articles:   72
Comments:   9
More Articles
36 comments   /   posted on Jan 09, 2012
Categories:   Windows Phone

There is not any doubt, the first thing you meet when you use Windows Phone are the tiles. These are the large squares on the home screen that identifies some applications and they are also a distinguishable character that make your Windows Phone unique.

As you know for sure, the tiles can be attached or detached from the home screen and some particular software can take advantage of double size tiles. While this is not a feature available to developers, in OS7.5, the tiles gained new features and a new set of APIs that you can use to enrich your applications. As an example you are now able to update your tiles from inside the application and you can use double faced tiles to improve information to the user. In this article I would like to explore these new features and show how to take advantage of them, while porting your software to the new operating system.

Accessing and changing your tile(s)

Once your application is running the user can have pinned its tile on the home screen. If this happened, you can have access to a bunch of tile's properties you can change at every time while the application is running, but please take note that it implies that the tile exists. Obviously, none of these APIs can work if your application is not pinned.

The root of your work is the ShellTile class that gives you access to a collection of ActiveTiles. At the very first place in this collection there is a structure that represents the main tile of your application. Reading the previous paragraph, you can expect this collection is empty when you application has not been pinned, but it is not true. The collection always contains at least one element, and you can update it every time also if the application's tile is not in the home screen. This does not cause a visible change but if the user choose to pin the application at a later time its tile will reflect these changes. The ShellTile class returned by this collection contains an "Update" method that is useful to change the tile's content:

   1: StandardTileData data = new StandardTileData
   2: {
   3:     Title = "My tile!",
   4:     Count = 10,
   5:     BackgroundImage = new Uri("/Background.png", UriKind.RelativeOrAbsolute),
   6:     BackTitle = "This is the back",
   7:     BackContent = "Hallo!",
   8:     BackBackgroundImage = new Uri("/Background.png", UriKind.RelativeOrAbsolute)
   9: };
  10:  
  11: ShellTile.ActiveTiles.First().Update(data);

The properties of the StandardTileData class reflect the parts of the tile and are divided in two categories: Front and Back. So, we have a "Title" property that reflects the title of the tile on the front side and the "BackTitle" that has the same meaning for the back side. This led to the consideration that in OS 7.5, tiles can have two sides available. It suffice you set the value of one of the "Back" properties and the tile automatically activates the back side on a random schedule.

Capture

Tiles have also a background image, usually of the size of 173x173 pixels, that fills the entire square. The image must reside in the project as a resource and we can refer to it with a relative uri that starts at the root of the project. So "/Background.png" refers to the standard image, usually created by visual studio in the default project. Of course you can set different images for each side of the tile.

If you generate images on the fly, while the application is running, you can also use isolated storage to peek up images to show in the tiles. For this purpose you have to generate images in the standard path "/Shared/ShellContent", and then use the "isostore:" prefix when you refer to it in the tile's uri. Here is an extended example that shows this tecnique with a generated background image. The image contains a simple gradient as shown on the left side.

   1: private const string TilePath = "/Shared/ShellContent/tile.jpg";
   2:  
   3: void MainPage_Loaded(object sender, RoutedEventArgs e)
   4: {
   5:     WriteableBitmap bmap = new WriteableBitmap(173, 173);
   6:  
   7:     for (byte x = 0; x < 173; x++)
   8:         for (byte y = 0; y < 173; y++)
   9:             bmap.Pixels[y * 173 + x] = (0xff << 24) | (x << 16) | y;
  10:  
  11:     using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForApplication())
  12:     {
  13:         if (file.FileExists(TilePath))
  14:             file.DeleteFile(TilePath);
  15:  
  16:         using (IsolatedStorageFileStream stream = file.CreateFile(TilePath))
  17:             bmap.SaveJpeg(stream, 173, 173, 0, 100);
  18:     }
  19: }
  20:  
  21: private void bCheckTiles_Click(object sender, RoutedEventArgs e)
  22: {
  23:     StandardTileData data = new StandardTileData
  24:     {
  25:         Title = "andrea",
  26:         Count = 10,
  27:         BackTitle = "This is the back",
  28:         BackContent = "Hallo!",
  29:         BackBackgroundImage = new Uri("isostore:/Shared/ShellContent/tile.jpg", UriKind.RelativeOrAbsolute)
  30:     };
  31:  
  32:     ShellTile.ActiveTiles.First().Update(data);
  33: }

Finally you probably noticed an asimmetry in front and back properties. While front properties have a "Count" value, the background can specify a "BackContent". The "Count" property is made to specify a number to show on the right-top corner. This may be useful to applications that can check for email messages and so on. The BackContent instead, is used to fill the main content of the tile background. The tile figure on the left side show the word "Hallo!" in the place where content is displayed.

Schedule tile updates

Once you configured your application's tile, your next need is probably to change the tile's content to notify the user about a service you are monitoring. This usually means use a time-based schedule that is able to check on a server if there is something to notify. Since OS 7.0, Windows Phone has a ShellTileSchedule. It was very limited because you was only able to update the background image, using a remote Uri to call on a scheduled basis. In OS 7.5 this has not changed a lot. The only thing we get added is the capability of also update secondary tiles (I will speak about secondary tiles in a few). You can connect the ShellTileSchedule to an arbitrary tile using the ActiveTiles collections as shown here:

   1: ShellTileSchedule schedule = new ShellTileSchedule(ShellTile.ActiveTiles.First())
   2: {
   3:     Interval = UpdateInterval.EveryHour, 
   4:     MaxUpdateCount = 0, 
   5:     Recurrence = UpdateRecurrence.Interval, 
   6:     StartTime = DateTime.Now,
   7:     RemoteImageUri = new Uri("http://xamlplayground.org/wp7updates/tile.jpg")
   8: };
   9:  
  10: schedule.Start();

The ShellTileSchedule constructor accept a reference to a ShellTile in the collection so you can schedule multiple updates, one for each tile of your application.

As I shown in the example of the previous article about background agents, Windows Phone 7.5 gives an additional opportunity to schedule tile updates. You are able to use a ScheduledAgent and from inside the agent you are able to access the ActiveTiles collection and update almost every property you think useful to notify the user, with the sole limitation of a fixed schedule of 30 minutes. In the Panoramio example I showed how to access GPS position and retrieve a random image from Panoramio to update the application tile with a local image. Please check out the previous article for a detailed explanation.

Using secondary tiles

A great new opportunity with Windows Phone 7.5, is the ability of configure more than a tile, to pin to the home screen. These tiles can work as shortcuts for services exposed by your applications. To make a practical example, you can think at secondary tiles to expose different locations for a weather channel or to have a shortcut to airplanes flights and so on. The sole limit is your fantasy.

A secondary tile is simply created using the static Create method only on user input. This means your application cannot create tiles automatically, but only when the user explicitly ask it, interacting with the application interface. To create the tile you have to fill a StandardTileData class and pass it to the method. As a result the application exits and the user is brought to the tile position in the home screen. This also means that you can only create a secondary tile for each session because, the process close the application every time. Here is the code to create the tile:

   1: private void PinToStart(string address)
   2: {
   3:     Server server = Repository.GetServer(address);
   4:  
   5:     if (server != null)
   6:     {
   7:         ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(
   8:             t => t.NavigationUri.ToString().EndsWith("server=" + address));
   9:  
  10:         if (tile == null)
  11:         {
  12:             string destFileName = CopyImageToShellContent(address);
  13:  
  14:             StandardTileData newTile = new StandardTileData
  15:             {
  16:                 Title = server.Name,
  17:                 Count = 0,
  18:                 BackgroundImage = new Uri("Background.png", UriKind.Relative),
  19:                 BackTitle = server.Name,
  20:                 BackBackgroundImage = new Uri(destFileName, UriKind.Absolute),
  21:                 BackContent = AppStrings.Title
  22:             };
  23:  
  24:             ShellTile.Create(new Uri("/Pages/VNCPanorama.xaml?server=" + address, UriKind.Relative), newTile);
  25:         }
  26:     }
  27: }

This sample, taken directly from the next release of my Silver VNC client for Windows Phone 7, shows how to create the tile. The important thing to note is the uri you have to pass to the Create method. This uri (called NavigationUri) is the one called when the user hits the pinned tile. It indicates the page inside your application that will be used as landing page for the request and can have multiple query string parameters to let the application decide how to answer to the request. Thanks to these parameters you can have multiple tiles that connect to the application with different actions. Inside the page that receive the user request you can parse the query string to evaluate the action to perform:

   1: protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
   2: {
   3:     this.txtName.Text = string.Empty;
   4:     this.txtAddress.Text = string.Empty;
   5:     this.Load();
   6:     this.EvaluateFromPinnedTile(e);
   7:     base.OnNavigatedTo(e);
   8: }
   9:  
  10: private void EvaluateFromPinnedTile(NavigationEventArgs e)
  11: {
  12:     if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)
  13:     {
  14:         Match match = Regex.Match(e.Uri.ToString(), ".*?server=(?<address>.*)");
  15:  
  16:         if (match.Success)
  17:         {
  18:             string address = match.Groups["address"].Value;
  19:  
  20:             Server server = Repository.GetServer(address);
  21:  
  22:             if (server != null)
  23:                 this.Connect(server);
  24:             else
  25:                 MessageBox.Show(string.Format(AppStrings.Message_UnknownServer, address));
  26:         }
  27:     }
  28: }

Into the OnNavigated method I call the EvaluateFromPinnedTile method that is responsible to check if the navigation occur because the user hit the pinned tile. In the method I check the NavigationMode property, that is always set to "New" when it is raised from a secondary tile and the use a regular expression to effectively check the incoming uri and retrieve the address. If the call is validated then I retrieve the Server information, from the local database, and then I call the Connect method to start the VNC connection.

To be double sure to not have exceptions I also check that the server exists on the database. Also if I delete the tile when the server is deleted from the database, this check is more defensive. Here is the deletion code:

   1: private void TryUnpinFromStart(string address)
   2: {
   3:     ShellTile tile = ShellTile.ActiveTiles.FirstOrDefault(t => t.NavigationUri.ToString().EndsWith("server=" + address));
   4:  
   5:     if (tile != null)
   6:     {
   7:         tile.Delete();
   8:     }
   9: }

While programming secondary tiles, you must be cautious because the user can always remove the pinned tile from the home screen, without the application get any warn about it. So please always be careful about what you get and always try to be in sync between secondary tiles and application data.

Tile your apps.

Tiles are probably the most distinctive feature you have in Windows Phone 7. As it happen for every hard decision you can only love or hate them. I meet lot of people that take tiles as an example of the wrong of the Windows Phone and lot of other people that think in the opposite way. My think is that for common people tiles are a great opportunity of access all the capabilities of the phone without have to deal with complicated interfaces. Only hit and pin, is the only thing you need. From the developer side, use tiles correctly gives you an additional gear to make you applications more flexible and effective. However, my think is that tiles are great; given I love the simplicity, they are one of the best features of my favorite phone.


Subscribe

Comments

  • rd3d2

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by rd3d2 on Jan 09, 2012 22:18
    .. and check out the new Tile Browser .. http://livetiles.co.uk/
  • FernandoCereceda

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by FernandoCereceda on Jan 13, 2012 13:41

    Nice Post ! Heading an update to "Frases del fútbol" soon!

  • PhilipAtherton

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by PhilipAtherton on Apr 30, 2013 23:00
    Blogs are good in which we get lots of information and convert that information to knowledge. assistance with essay | written essay | bachelor essay | essays at low cost | online Essay service
  • thewidi

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by thewidi on May 01, 2013 09:24
    Helpful info. judi online Fortunate me I found your site by chance, and I am surprised why this accident did not took place earlier! I bookmarked it.
  • jhon0123

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by jhon0123 on May 01, 2013 10:23
    aftec concrete fence
    Great, great blog! Hope I'm not bothering you, but I have an interesting idea, my friend for your site.I am a fan of your blog, I spent a lot of time to make and read your site.Also very pleased that you share with us your blog
  • LauraNewby

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by LauraNewby on May 02, 2013 11:01
    Thanks for sharing this information.And I'll love to read your next post too. essays help,, college essay,, complete my essay,, essay service online,, expert essay writers
  • ethanlord

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by ethanlord on May 03, 2013 13:34
    Valuable information ..I am delighted to read this article..thank you for giving us this useful information. dissertation help in UK , pay anyone to do my dissertation in a week , dissertation editing service providers , undergraduate dissertation providers , law dissertation providers , purchase dissertation.
  • nike741

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by nike741 on May 03, 2013 20:11

    This is a wonderful post. I will share it to everynone,It is great to have the opportunity to read a good quality article with useful information on topics that plenty are interested on. I concur with your conclusions and will eagerly look forward to your future updates............: www.welivebetter.com

  • IrfanBashir

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by IrfanBashir on May 05, 2013 20:49
    Attractive portion of content. I simply stumbled upon your website and in accession capital to claim that I acquire in fact enjoyed account your weblog posts. Anyway I'll be subscribing in your feeds and even I achievement you access constantly fast. veterinaire laval
  • Joiike

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by Joiike on May 05, 2013 21:46

    WOW!!! What I have found from your site, it is actually highly content. You have spent long time for this post. It’s a very useful and interesting site. Thanks!

    buy research papers

  • JackieMarie

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by JackieMarie on May 07, 2013 00:49
    Nice one… This is exactly what I was looking for. Thanks for great writing!
    Essay help || buy essay || write my assignment || UK coursework writing help || need to buy coursework || how to get coursework writing service
  • MariamMcNess

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by MariamMcNess on May 09, 2013 05:54

    In genuineness prosperous content and very helpful in sequence. I got it my elucidation from over here. I very much urge his/her workings with the constructive enlightening information. Thanks a lot………..

    divorce business appraisal 

  • MariamMcNess

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by MariamMcNess on May 11, 2013 06:15

    This is the original point in time I visited this blog. Really this is breathtaking effort with the blog. It is exceedingly contentment to search out it as I got mammoth helps right here.  I decidedly welcome the bloggers workings and will kill time for more post from the supervision.

    homes for sale El Dorado Hills

  • KomalSinha

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by KomalSinha on May 13, 2013 16:22
    telefonkatalogen.biz
    I found this is an informative and interesting post so i think so it is very useful and knowledgeable. I would like to thank you for the efforts you have made in writing this article
  • MariamMcNess

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by MariamMcNess on May 15, 2013 06:17

    Really rich content and very useful information. I found my problem’s solution starting over here. I exceedingly advocate his/her machinery by means of the valuable enlightening information. Thanks a lot………..

    footprints recruiting

  • Duncan

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by Duncan on May 16, 2013 15:16

    Truly remarkable labor with the blog. I do like your inflexible service and will wait for more post from you as post gave me gratification and gives some helps to do same work right here. Thanks a lot………

     discounts for control

  • nike741

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by nike741 on May 16, 2013 21:46
    It is vital to urge a bigger education significantly with our prime demands these days. top essay writing services generally generating a certification isn’t enough to extend your money and social rank alive. the bulk of the effective folks in today.
  • sumty

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by sumty on May 17, 2013 12:07
     Truly remarkable labor with the blog. I do like your inflexible service and will wait for more post from you as post gave me gratification and gives some helps to do same work right here. sammelgut transport Thanks a lot…
  • cyberjudi

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by cyberjudi on May 17, 2013 21:53

    Agen bola terbesar dan agen sbobet ibcbet terpercaya.Menyediakan taruhan judi bola di indonesia dan game casino sbobet casino online & 338A

  • Ahiek

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by Ahiek on May 18, 2013 00:00
    Thank you for publish this information very useful! You may see my site paper writing I’m still waiting for some interesting think from your side in your next post thanks.
  • filmstreaming

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by filmstreaming on May 18, 2013 08:05
    film streaming  generally generating a certification isn’t enough to extend your money
  • ashleymckinle

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by ashleymckinle on May 18, 2013 11:03
    I have visited this site a couple of times now and i have to say that i find it quite exeptional actually. womensinterestsarticles.info it'll be nice to read more in the future. Interesting blog. It would be great if you can provide more details about it. Thanks you. You really make it seem so easy with your presentation but I find this topic to be really something which I think I would never understand.
  • daizewe

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by daizewe on May 18, 2013 16:14

    In reality splendid occupation with the blog. I do in the vein of your rigid effort and will linger for more post from you as post gave me joy and gives some helps to do same work right here. Thanks a lot…………………………

    sell your home
  • daizewe

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by daizewe on May 18, 2013 16:15

    In truth breathtaking job with the blog. I do approximating your stiff exertion and will hang around for more post from you as post gave me delight and gives some helps to do same work right here. Thanks a lot…………………………

    El Dorado Hills

  • nike741

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by nike741 on May 18, 2013 22:44
    Ahealth clinic approved below the  provisions  of  chapter one  hundred cardinal of the laws of 19 hundred seventy-eight; or physics lab help another school-based health or  dental  clinic authorized  by  the department  of  health consistent  to  article twenty-eight of the general public health law.
  • GaryRoberts

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by GaryRoberts on May 20, 2013 01:15

    This is a celebrated post. I will share it to everyone; it is vast to have the break to read a good distinction article with useful information on topics that abundance is concerned on.custom cake toppers for weddings

  • Michael2013

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by Michael2013 on May 20, 2013 10:55
    In genuineness prosperous content and very helpful in sequence. Monterey Real Estate I got it my elucidation from over here. I very much urge his/her workings with the constructive enlightening information.
  • Arian

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by Arian on May 21, 2013 00:46

    First of all thanks for the post. Actually it is overwhelming post. I do like your firm workings and be grateful for your idea. I can pass on you another site where one can obtain huge assistances about tutoring. To learn moiré, please click here. Thanks……

     business valuation in Columbus

  • Agnes

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by Agnes on May 21, 2013 05:51
    Legit NeverWinter Gold at MMO Game master site. [url=http://www.goldceo.com/NeverWinter/NeverWinter-gold.shtml]neverwinter money[/url] NeverWinter Online Gold farmed by our real professional players. [url=http://www.goldceo.com/NeverWinter/NeverWinter-gold.shtml]neverwinter gold[/url] We Sell cheap NeverWinter gold, buy safe gold no banned here. Abundant of neverwinter Gold hot for sale in our store! To buy neverwinter Gold with immediate [url=http://www.goldceo.com/NeverWinter/NeverWinter-gold.shtml]neverwinter zen[/url] delivery can help you upgrade fast. Efficient neverwinter Power leveling [url=http://www.goldceo.com/NeverWinter/NeverWinter-gold.shtml]neverwinter Astral Diamonds[/url] ensure you enjoy more fun!
  • Agnes

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by Agnes on May 21, 2013 05:51
    Legit NeverWinter Gold neverwinter money at MMO Game master site. NeverWinter Online Gold farmed by our real professional players. We Sell cheap NeverWinter gold, neverwinter gold buy safe gold no banned here. Abundant of neverwinter Gold hot for sale in our store! neverwinter zen To buy neverwinter Gold with immediate delivery can help you upgrade fast. neverwinter Astral Diamonds Efficient neverwinter Power leveling ensure you enjoy more fun!
  • Rachael

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by Rachael on May 21, 2013 05:52
    Cheapest Silkroad gold, fast delivery and safest sro gold, Silkroad Silk all servers in stock hope you buy Silkroad online gold, give extra bonus and best service to you. We are the leading and professional online Silkroad gold store. Sro silk Buy cheap and soon Silk road gold from us,enjoy safe and fast buy sro gold delivery.
  • Rachael

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by Rachael on May 21, 2013 05:53
    Order and Chaos Online order and chaos gold Wiki is a community site that anyone can contribute to. Buy order and chaos gold Discover, share and add your knowledge!Order and Chaos hack for iPhone and Android for runes in Order and Chaos. cheap order and chaos gold Order and Chaos hack no jailbreak or root.
  • Paige

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by Paige on May 21, 2013 05:54
    Age of Wushu (AoW) is the world’s first true Wuxia themed MMORPG, Age of Wushu Taels with cutting edge graphics and innovative gameplay. Age of Wushu Gold Relive more than 2000 years of Wuxia tradition in Snail Games USA’s colossal MMORPG, Age of Wushu. In your journey to master the ancient Chinese art of Wushu, delve into your character’s unique story, Age of Wushu currency face the consequences for every action, and fulfill your destiny.
  • Paige

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by Paige on May 21, 2013 05:54
    shaiya gold Became been Duke due, Nukem in making 1996. Its groundbreaking shaiya gold hack 2010 shaiya gold hack code, the is due developed. Mac sh…ey everyone, this is the new Shaiya Gold Hack,shaiya op it comes with Auto-Fill and many other features, shaiya money the previous patched
  • EllenPage

    Re: Windows Phone 7.5 - Using advanced tiles API


    posted by EllenPage on May 21, 2013 21:48

    Wonderful! Actually wealthy content and extremely helpful in sequence. I got it my answer from over here. I extremely advocate his/her mechanism with the helpful educational information. Thanks a lot………..

     New Jersey business appraisal

Add Comment

Login to comment:
  *      *       

From this series