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

image

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

StandardTileData and ShellTile

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

clip_image002

You can set data for tile as below,

clip_image004

StandardTileData class has following properties. You can set value of these properties to set as 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

Below code snippet will update a live tiles with title and count.


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

namespace liveTiles
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            UpdateLiveTiles();
        }

        private void UpdateLiveTiles()
        {
            ShellTile currentTiles = ShellTile.ActiveTiles.First();
            var tilesUpdatedData = new StandardTileData
                                  {
                                      Title = "Live Tiles ",
                                      Count = 10,
                                      BackTitle ="Back Title"

                                  };

            currentTiles.Update(tilesUpdatedData);

        }
    }
}



Live tile will get updated as below,

image

Create a Live Tile

Below code snippet will create a new live tiles. 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 above code snippet is uri. On click of create live tile user will navigate to given xaml.

clip_image001

Updating created Live Tile

To update a particular tile, first you need to fetch the tile with 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,

clip_image001[6]

This was all about basic of live tiles in windows phone 7.5 without using push notification.

I hope this post was useful. Thanks for reading Smile

Advertisements

7 thoughts on “Live Tiles in Windows Phone 7.5 or Mango phone

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