In this article we will discuss about how to update tile without push notification. You can update title, count, backgroundimage, backtitle, backcount and backbackgroundimage. We will consider to update title, count and backgroundimage in this article.
Let's write code to see how we can update primary tile.
Step 1: Create two image of size 173X173 like below.
Step 2: Create a folder images and place both the above images in that folder. Once you add the images in the folder change the Build Action of the image from Resource to Content.

Step 3: Now add two textboxes and the above created image inside the contentpanel of MainPage.xaml.
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <TextBlock Height="30" HorizontalAlignment="Left" Margin="164,96,0,0" Name="textBlockTitle" Text="Title" VerticalAlignment="Top" FontSize="18" /> <TextBox Height="72" HorizontalAlignment="Left" Margin="197,74,0,0" Name="txtTitle" Text="" VerticalAlignment="Top" Width="260" /> <TextBlock Height="30" HorizontalAlignment="Left" Margin="46,171,0,0" Name="textBlockBackgroundImage" Text="Background Image" VerticalAlignment="Top" FontSize="18" /> <Image x:Name="MaroonButton" Source="images/Maroon.jpg" Width="50" Height="50" Margin="130,160,115,0" VerticalAlignment="Top" MouseLeftButtonDown="MaroonButton_MouseLeftButtonDown" Opacity=".5" /> <Image x:Name="OrangeButton" Source="images/Orange.jpg" Width="50" Height="50" Margin="260,160,115,0" VerticalAlignment="Top" MouseLeftButtonDown="OrangeButton_MouseLeftButtonDown" Opacity=".5" /> <TextBlock Height="30" HorizontalAlignment="Left" Margin="140,249,0,0" Name="textBlockCount" Text="Count" VerticalAlignment="Top" FontSize="18" Width="60" /> <TextBox Height="72" HorizontalAlignment="Left" Margin="197,230,0,0" Name="txtCount" Text="" VerticalAlignment="Top" Width="260" InputScope="Number" /> <Button x:Name="PrimaryButton" Content="update primary tile" Height="75" Margin="23,551,23,0" VerticalAlignment="Bottom" Click="PrimaryButton_Click"/> </Grid>
Step 4: Add image handler for the image. The selected image will be displayed on the tile.
private void MaroonButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { MaroonButton.Opacity = 1; OrangeButton.Opacity = .5; }
private void OrangeButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { MaroonButton.Opacity = .5; OrangeButton.Opacity = 1; }
Step 5: Add button handler which will update the tile on click of it. Based on the image selected background image of tile will be updated.
private void PrimaryButton_Click(object sender, RoutedEventArgs e) { ShellTile PrimaryTile = ShellTile.ActiveTiles.First(); if (PrimaryTile != null) { StandardTileData tile = new StandardTileData(); if (MaroonButton.Opacity == 1) tile.BackgroundImage = new Uri("images/Maroon.jpg", UriKind.Relative); else if (OrangeButton.Opacity == 1) tile.BackgroundImage = new Uri("images/Orange.jpg", UriKind.Relative); tile.Count = Convert.ToInt32(txtCount.Text); tile.Title = txtTitle.Text; PrimaryTile.Update(tile); } }
Step 6: Now run the application and pin to start.

The app will be pinned on the start screen.

Click on the app to get below screen to update the tile.

Enter titile text, background image and number in the count textbox. Now press update primary tile button to update tile. Count should be between 1-99 and 0 to clear the count. Now press hardware window button. The title, image and count will be updated like below example.

This ends the article of updating primary tile in Windows Phone 7.
|