Click here to Skip to main content
Click here to Skip to main content
Go to top

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

, 11 Sep 2012
Rate this:
Please Sign up or sign in to vote.
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.

#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);
}

License

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

Share

About the Author

sam stokes
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 --
| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 12 Sep 2012
Article Copyright 2012 by sam stokes
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid