Live Tiles in Windows Phone 7.5 or Mango phone

In Windows Phone 7 Live tiles was only possible through Push notification. However Windows Phone 7.5 (code name: Mango) allows developers to update, create primary and secondary tiles without push notifications. In this post, we will walkthrough the process.

Live Tiles in Windows Phone 7.5 or Mango phone

To create and update live tiles essentially you need to work with the below classes

ShellTile

StandardTileData


You can get the instance of current tile for an application as below,

Live Tiles in Windows Phone 7.5 or Mango phone

You can set the data for tile as below,

Live Tiles in Windows Phone 7.5 or Mango phone

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

Update a Live Tile

The below code snippet will update a live tile with title and 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); 
        }       
    }
}


Live tile will get updated as below,

Live Tiles in Windows Phone 7.5 or Mango phone

Create 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);
        }


Important point to note in the above code snippet is the uri. On click of create live tile user will navigate to given XAML.

Live Tiles in Windows Phone 7.5 or Mango phone

Updating created Live Tile

To update a particular tile, first you need to fetch the tile with a query string as below,

       
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);
        }

Tile will get updated as below,

Live Tiles in Windows Phone 7.5 or Mango phone

This was all about basic of live tiles in Windows Phone 7.5 without using push notifications.

I hope this post was useful. Thanks for reading.

Up Next
    Ebook Download
    View all
    Learn
    View all