×
Namespaces

Variants
Actions

How to pin the application tile to the start screen from code

From Nokia Developer Wiki
Jump to: navigation, search
Featured Article
20 Oct
2013

This article shows how to pin the application to the start screen from code (dynamically).

WP Metro Icon UI.png
SignpostIcon XAML 40.png
WP Metro Icon WP8.png
SignpostIcon WP7 70px.png
Article Metadata
Tested with
SDK: Windows Phone 8.0 SDK, Windows Phone 7.1.1 SDK
CompatibilityArticle
Created: munjalrohit (16 Sep 2013)
Last edited: saramgsilva (02 Nov 2013)

Contents

Overview

The application tile is the default tile created for an app when the user pins it to the start screen. While you can set it's default values, there is no way to manually create the "real" application tile in code.

Solution

While you can't create the application tile in code, you can create a secondary tile in code that looks and behaves exactly the same. The code to create a secondary tile is given in Working with Live Tiles on Windows Phone#Secondary Tile.

The special "trick" here is to check whether the application tile has already been defined before creating the "pseudo" application tile. Do this by testing whether the tile's navigation URI is the main page of the app (in this case MainPage.xaml). Then we create a secondary tile using the same field values and with navigation URI of the app start page.

private void PinToStart()
{
StandardTileData standardTileData = new StandardTileData();
standardTileData.BackgroundImage = null;
standardTileData.Title = "Pined From Application";
standardTileData.Count = 5;
standardTileData.BackTitle = "Back Title Data";
standardTileData.BackContent = "Back Content Data";
standardTileData.BackBackgroundImage = null;
 
// Check if the application tile has already been defined - this is a tile that links to the app main page
ShellTile tiletopin = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("MainPage.xaml"));
if (tiletopin == null)
{
//Create ShellTile linking to main page of app
ShellTile.Create(new Uri("/MainPage.xaml", UriKind.Relative), standardTileData);
}
else
{
MessageBox.Show("Application is already Pinned");
}
}

Test code

None provided.

References

This page was last modified on 2 November 2013, at 17:56.
237 page views in the last 30 days.
×