Continuing my series of Blog posts that distill the presentations I’m giving this month in Europe and the UK, today I’ll take a look at creating a Live Tile.
Live tiles tell the user that something interesting is happening in your application, or that you have new information for them.
Live tiles are an essential and exciting part of Windows 8 and creating a Live tile is not very difficult. In fact, creating a simple Life tile is, well, simple.
To start, create a new blank application and name it LiveTile. The very first thing to do is to add the NotificationsExtensions project that Microsoft are* shipping with the SDK and with the Sample applications on tiles.
*I’m in the UK right now, and here corporations are plural(!)
On the home page, create a button,
1: <Button Name="CreateLiveTile"
2: Content="Create"
3: Click="CreateLiveTile_Click_1" />
When the button is clicked, we’re going to send text to the tile.
Note that there are two ways to send text to a tile:
- From within the application as we are doing here
- Using the Windows Notification Service (NWS) covered in a future blog post
In the event handler for the button click event, we start by creating a wide and a square tile with the new text we want to display,
1: private void CreateLiveTile_Click_1(object sender, RoutedEventArgs e)
2: {
3: ITileWideText03 tileContent = TileContentFactory.CreateTileWideText03();
4: tileContent.TextHeadingWrap.Text = "Jesse's Tile Notification";
5:
6: ITileSquareText04 squareContent = TileContentFactory.CreateTileSquareText04();
7: squareContent.TextBodyWrap.Text = "Jesse's Tile Notification";
We then attach the square tile to the wide tile,
1: tileContent.SquareContent = squareContent;
Create an instance of TileNotification by calling CreateNotification on the wide tile,
1: TileNotification notification = tileContent.CreateNotification();
Create an instance of TileUpdater by calling CreateTileUpdaterForApplication on the TileUpdateManager,
1: TileUpdater updater = TileUpdateManager.CreateTileUpdaterForApplication();
Pass the notification to the Update method of the TileUpdater,
1: updater.Update(notification);
That’s all there is to it. If you switch to your tile in the start menu, you’ll see the message pop into view.
You can find the source for this example here
4 Responses to Creating A Live Tile