Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / Win32

Super Simple C++ Win8 Live Tile Text Notification

0.00/5 (No votes)
12 Sep 2012Ms-PL2 min read 13.2K  
How to implement live tile notification in just a few lines of code

Introduction

This "tip" shows the basic mechanics used to create a basic live tile notification using text.  

To start, I created a click event in XAML code which kicked off an event to send a simple text message to the application tile.

To find out how to use images for your tiles see:

Use this article to figure out how to write the code needed to send a message or notification to a Live Tile in Windows 8.

Background

Create a new C++ Blank XAML project and add the images as shown in the articles referenced. 

Use your own images that meet the requirements as shown in the article.

Using the code

  • Build the C++ application in Visual Studio 2012 Express or Visual Studio 2012 Pro/Premium/Ultimate version. 
  • Run the code, either in the simulator or on a Windows 8 machine, push the windows/flag key and look for your application, note the tile on the "Start" screen. 
  • Then go back to the running application, click the "Send Link" button. 
  • Push the windows/flag key to go back to the "Start" screen, if there has been no change, wait a few seconds and you will see the text appear (in this case the word: Boo, because it is so scary easy). 
  • For more explanation see my blog at: http://aka.ms/tilenotification
C++
#include "pch.h"
#include "MainPage.xaml.h"

using namespace LiveTileFun;
using namespace Platform;
using namespace Windows::Foundation;
using namespace Windows::Foundation::Collections;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Controls;
using namespace Windows::UI::Xaml::Controls::Primitives;
using namespace Windows::UI::Xaml::Navigation;
//*******************************************************
//Add the next two lines ********************************
using namespace Windows::UI::Notifications;
using namespace Windows::Data::Xml::Dom;
//*******************************************************
//*******************************************************

MainPage::MainPage()
{
    InitializeComponent();
}

void MainPage::OnNavigatedTo(NavigationEventArgs^ e)
{
    (void) e;    // Unused parameter
}

void LiveTileFun::MainPage::DemoTile1(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
    XmlDocument^ tileXml = TileUpdateManager::GetTemplateContent(TileTemplateType::TileSquareText01);
    
    XmlNodeList^ tileTextAttributes = tileXml->GetElementsByTagName("text");
    tileTextAttributes->Item(0)->InnerText = "Boo!";

    TileNotification^ tileNotification = ref new TileNotification(tileXml);
    TileUpdateManager::CreateTileUpdaterForApplication()->Update(tileNotification);
}

Points of Interest

Be careful, if you try to use a Tile template enumeration that doesn't match what is avaiable in the tile, it will fail silently.  What does that mean?  If you send a square tile notification to a wide tile, then nothing will happen.  Also, there is a little latency in the message sending so make sure to wait a few seconds if you don't see the notification.

History

v1.1a: 9/11/2012

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)