Live Tile Creation Without Push Notification in Windows Phone 7 Mango

With the launch of Windows Phone 7 came “Live Tiles” which provided a glimpse as to what information was aggregating amidst the application it represented.  Information as to how many tweets or emails recieved would be represented my a numeric value found on the tile itself.  The challange to developers though was the fact that a Live Tile could only be created alongside push notification to update said tile.  This is no longer the case with the introduction of Mango update for Windows Phone.  The Mango update allows developers to update, create primary and secondary tiles without the requirement of push notification.

To create and update live tiles essentially you will need to work with the ShellTile and StandardTileData classes.

You can get the instance of current tile for your application as provided in the example below:

ShellTile currentTiles = ShellTile.ActiveTiles.First();

You can set the data for you tile as demonstrated below.

var tilesUpdateData = new StandardTileData
         {
                 Title = “Live Tiles “,
                 Count = 10,
                 BackTitle = “Back Title”
         };

StandardTileDataclass has following properties. You can set value of these properties to set the data of live tiles.

  1. public Uri BackBackgroundImage
  2. public string BackContent
  3. public Uri BackgroundImage
  4. public string BackTitle
  5. public int? Count

Updating a Live Tile

The code snippet below will update a live tile with a title and a numeric count.

using System.Linq;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using WindowsPhoneApplication3;

namespace liveTiles
{
    public partial class MainPage : PhoneApplicationPage
{
    // Constructor
        public MainPage()
        {
          InitializeComponent();
          UpdateLiveTiles();
        }      
          private void UpdateLiveTiles()
        {
            ShellTile currentTiles = ShellTile.ActiveTiles.First();
            vartiles UpdatedData = new StandardTileData
            {
                Title =“Live Tiles “,
                Count = 10,
                BackTitle = “Back Title” 
            };
            currentTiles.Update(tilesUpdatedData); 
        }       
    }
}

The Live Tile will now get updated as shown in the example below.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Creating a Live Tile

The below code snippet will create a new live tile. Creation of live tile is exactly same as updating of live tile but to call Create function.

        private void CreateLiveTile()
        {
            var newTile = new StandardTileData()
            {
                Title = “Blogs Update”,
                BackgroundImage = new Uri(“background.png”, UriKind.Relative),
                Count = 42,
            };
            var uri = “/LiveTileUserControl.xaml?state= Live Tile”;
            ShellTile.Create(new Uri(uri, UriKind.Relative), newTile);
        }

An important point to note in the above code snippet is the uri. On clicking on the created live tile the user will navigate to the given XAML.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Updating The Created Live Tile

First step is to fetch the tile with a query string to allow the update to occur as show in the following example.

        private void UpdatingCreatedTile()
        {
            var uri = new Uri(“/LiveTileUserControl.xaml?state= Live Tile”, UriKind.Relative);
            ShellTile  tileToUpdate = ShellTile.ActiveTiles.Where(t => t.NavigationUri == uri).FirstOrDefault();
            var tilesUpdatedData = new StandardTileData
            {
                Title =“Created Tiles Updated “,
                Count = 45,
                BackTitle = “Back Title”

            };

            tileToUpdate.Update(tilesUpdatedData);
        }

This will then result in the tile getting updated as show below.

Advertisements

One thought on “Live Tile Creation Without Push Notification in Windows Phone 7 Mango

  1. Incredible… and to think the user only sees the pretty Tile bobbing up and down…while the OS is running under complicated web of code and run commands.

    Thanks…plenty of info to spare….Windows Phone deserves all your posts…keep them up

    Visit my website, Premier Microsoft http://premiermicrosoft.wordpress.com
    Microsoft news, updates and reviews

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s