Click here to Skip to main content
15,880,469 members
Articles / Desktop Programming / Win32
Tip/Trick

Super Simple C++ Win8 Live Tile Text Notification

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
12 Sep 2012Ms-PL2 min read 13K   1  
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

This article was originally posted at http://aka.ms/tilenotification

License

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


Written By
Instructor / Trainer Microsoft
United States United States
Sam Stokes works for Microsoft as a technology evangelist and is focused on working with colleges, students and professors.

Comments and Discussions

 
-- There are no messages in this forum --