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

Super Simple Live Tile Notification Using an Image (C++)

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
11 Sep 2012Ms-PL 7.2K  
This sample demonstrates how to use the Tile Template, specifically the TileSquareImage and an image.

Introduction

This sample demonstrates how to use the Tile Template, specifically the TileSquareImage and an image.

Using the Code

Unzip the file, run the solution.

The solution will run a Windows 8 application with no snap/fill/full features.

To see it working, make sure to use the Windows/flag key to switch to the start screen, find your icon and then hit the flag to go back to the running application. 

Click the button and then use the Windows/flag key again, quickly, and you will see the new image appear. (And yes, this is a variation on an earlier tip.)

For more information, see my blog.

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)
{
//************************************
	//This line can remain the same, except for the template, in this case TileSquareImage
	//If you use the wrong template, then an error is thrown
	//***************************
	XmlDocument^ tileXml = 
		TileUpdateManager::GetTemplateContent(TileTemplateType::TileSquareImage);
	//****************************
	// This line changes, now you look for the default tag of image, tileImageAttribute is
	// a variable that I created or took from an example, it is not a keyword
	//*****************************	
        XmlNodeList^ tileImageAttributes = tileXml->GetElementsByTagName("image");
	//*****************************	// the static_cast is used to move 
	// the image in to the element Item 0 or the first item
	// in this case, you only get a single item, so you must use item 0, otherwise you get an
	// error
	static_cast<XmlElement^>(tileImageAttributes->Item(0))->
					SetAttribute("src", "ms-appx:///Assets/Winner150.png"); 
//**************************
// Send your tile notification and then update it, this code did not change
// It would change if you modify the XmlDocument variable titleXml
//*******************	
TileNotification^ tileNotification = ref new TileNotification(tileXml);
	TileUpdateManager::CreateTileUpdaterForApplication()->Update(tileNotification);
}
This article was originally posted at http://aka.ms/sx0oo1

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 --