Tiles in Windows Phone Mango – Create and Delete Secondary Tile

This is the 4th part of my series on the Tiles in Windows Phone Mango .

In this Blog post , i will explain how one can create Secondary Tiles in Windows Phone .

The Secondary Tile is generally created from the App programatically based on the users interaction .

A simple scenario where the secondary tiles can be used are the Weather Application or a Chat Application .

The Weather Appllication might provide the user with the option of pinning only the selected locations to the start screen of the Windows Phone 7 .

The Chat Application might allow the user to pin a user to the start screen .

So , how do we create the Secondary Tile in Windows Phone ? .

We can again use the StandardTileData Class to define the properties of the Tile and use the Create Method of the Shell Tile to create the secondary Tile .

The below sample sourcecode should create one .

/// <summary>
/// Creates the secondary tile.
/// </summary>
public void CreateSecondaryTile()
{
   StandardTileData TileInfo = new StandardTileData
   {
     BackgroundImage = null,
     Title = "iSenthil",
     Count = 26,
     BackTitle = "Ginktage",
     BackContent = "My Secondary Tile Sample",
     BackBackgroundImage = null
   };
   ShellTile.Create(new Uri("/Page1.xaml?Place=Bangalore", UriKind.Relative), TileInfo);
}

There is an issue with the above one … When you try to call the above more than once , you will get the following error

 

We should create the Tile only if it is not found . So , its necessary to validate and check if the Tile Exists .

This can be done by verifying the Tile Name “Place=Bangalore” in ShellTile.ActiveTiles.FirstOrDefault() and check with the NavigationUri if the name exists .

You can delete the secondary Tile by finding the tile from the ActiveTiles and calling the Delete method of the found ShellTile

/// <summary>
/// Deletes the tile.
/// </summary>
private void DeleteTile()
{
   ShellTile TileToDelete = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Place=Bangalore"));
   if (TileToDelete != null)
   {
     TileToDelete.Delete();
   }

}

To Update , you can use the Update Method of the ShellTile like the one that was described in my previous post on Application Tile .

via WindowsPhoneRocks.com

 

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

No Responses

Leave a Reply


x

Interesting BlogPosts to read

Download - Pokemon Go for for Windows 10 (Third Party app)
Pokemon Go is one of the popular AR games for android and iOS devices and now , the game is made ava...
Open Wordpad from command line in Windows
You can use the command "Write" from command line in Windows to open the WordPad application.D:\>...
Popular cross-platform (android and iOS) to-do list app
In this blog post, we will cover some of the popular to-do list app that is available on different p...