In this article I will discuss how to pin any application on Windows Phone 7 using button or any other control action but without using pin to start option of context menu which you get when you hold any application for few seconds.
Let's write code.
Step 1: Add two buttons inside content panel of MainPage.xaml. The first button pintostart will pin the application to start and delete button will delete the pinned application from start.
<Button x:Name="pintoStart" Margin="20,00,0,0" Height="80" Click="pinToStart_Clicked" Content="Pin To Start" />
<Button x:Name="delete" Margin="20,200,0,0" Height="80" Click="delete_Clicked" Content="Delete" />
Step 2: Add Microsoft.Phone.Shell using directive.
Step 3: Now place event handler pinToStart_Clicked in the code behind of MainPage.xaml.
Create a StandardTileData which lets you add backgroundimage, tite, count, backtite, backcontent and backbackgroundimage.
Now use ShellTile to pin to start. Before pinning any tile we need to check whether it is already pinned or not otherwise InvalidOperationException will be thrown.
private void pinToStart_Clicked(object sender, RoutedEventArgs e)
StandardTileData standardTileData = new StandardTileData();
standardTileData.BackgroundImage = null;
standardTileData.Title = "Pinned by button";
standardTileData.Count = 26;
standardTileData.BackTitle = "Pinned";
standardTileData.BackContent = "Secondary Tile";
standardTileData.BackBackgroundImage = null;
ShellTile tiletopin = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("MainPage.xaml"));
if (tiletopin == null)
ShellTile.Create(new Uri("/MainPage.xaml", UriKind.Relative), standardTileData);
Step 4: Place delete_Clicked event handler which will delete the tile from start.
private void delete_Clicked(object sender, RoutedEventArgs e)
ShellTile TileToDelete = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("MainPage.xaml"));
if (TileToDelete != null)
This ends the article of pin to start from any control apart from pin to start from context menu provided by Windows Phone 7.