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.
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,
You can set data for tile as below,
StandardTileData class has following properties. You can set value of these properties to set as data of live tiles.
- public Uri BackBackgroundImage
- public string BackContent
- public Uri BackgroundImage
- public string BackTitle
- 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,
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.
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,
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
Leave a Reply